Cannot connect to SQL Server from ASP.NET MVC app - asp.net-mvc

I have an ASP.NET MVC app that has on a hosted server for over a year, connecting to SQL Server. I've had to change hosting services, the new one supports MVC 1.0. I've also moved a non MVC ASP app to the same hosting service.
Now, MY MVC based app retturnes this error when I try to validate a user login.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Now, the non-MVC app can access the exact same database and authenticate users just fine. The MVC app, when run from my dev box connects fine. It also run/connects/authenticates without problem when I install and run the site from an internal SQL 2008 server running IIS 7.
I, along with the hosting support techs, am at a loss how the exact same connect string works every where except on the hosted server, and only when run from inside an ASP.NET MVC web app.
Any ideas would be greatly appreciated.

Are you using SQL authentication or Windows authentication in your connection string? If you're using Windows authentication the default account used for IIS apps is NETWORK SERVICE. You would need to allow this user access to your database.
You might want to check what user the application pool is running under. It's possible the non-MVC application is running under a different user than the MVC application.

Related

Ask for username and password before loading ASP.NET MVC 5 application

I am running an ASP.NET MVC 5 application on a Windows 2019 server with IIS 10. Now I want to set the IIS to pop up a window asking for a specific user with password before loading the web application in the browser. It is important that the prompt appears before the application accepts the client's requests. So actually before the application is started on the web server.
I can remember that something like this used to be possible with a .htaccess file. Is it possible to implement this in IIS 10 with the Web.config file somehow? In my Web.config I have already entered a http to https rule. So it would not be a security leak, because the connection is encrypted. Is it possible to configure IIS to ask for a specific password and username before starting the web application?
Thanks.
As can also be seen in the comments under the question, there is no IIS build-in solution for this requirement. The integration of third-party software for this requirement has not been considered.

How to publish and host a MVC4 application in your domain?

I have a webdomain www.MyDomain.com and a MVC4 web application MyMVCWebApp.
First I publish the application to a local destination.
For instance: C:\TempLocation
And then I host it to my domain with a FTP-tool (FileZilla??)
The files will be hosted but I can't find the webpage.
Which url do I have to write?
http://www.MyDomain.com/MyMVCWebApp/Home/Index.chtml or something?!
Do I have change the settings in my web.config?
What do I have to do?
You can't host an application on a domain.
An application is hosted on a web server. A domain name is only a way to translate an easy to remember address like "www.google.com" to the web server ip address which looks like 173.194.66.104
It is possible to purchase a domain without a web server.
So before going further:
Check if you actually bought a domain only, or a domain with a server
Your domain should redirect to your server ip address, you can see if he is correctly configured by opening a command prompt and doing
C:\> ping www.yourdomain.com
If this is not the case you will need to update the A record of your domain, and wait for the update to be replicated on DNS server worldwird.
If you have a managed server, you should check your hosting provider website. They usually provide in depth documentation, and they all have a different way to do things. Most of the time indeed you will be able to upload your files using a FTP software such as Filezilla.
However, in order to host a MVC 4 application you need a server with
the IIS web server, which means that you need a Windows server. So if
you have a Linux server, you should contact your hosting provider
support and tell them you made a mistake during your order. (It is
possible to host a MVC 4 application on Linux, but I don't think it
is often provided on managed servers)
If you have a dedicated server you are on your own.
The URL you will have to write to access your application will depends on what you have configured in the RegisterRoutes method of the RouteConfigs.cs file.
I recommend you to watch the last video on this page to have a better overview of the possibilities.

ASP.NET Users not publishing to Azure

I've got a simple MVC 4 application with a user and role defined in the ASP.NET Configuration. They work fine locally (Running with F5) but when published to Azure Web Site the users don't exist or at least, when trying to log in I can't. Could either be the user doesn't exist or that the passwords isn't matching.
e.g. I have a page for Admins only, I have one admin user. Locally I created the user and role in the ASP.NET Configuration page and I can log in as Admin and access the secured page. After publishing to Azure Web Site I can't log in as Admin.
Can anyone help? How do I publish my ASP.NET Configuration?
I'm using Visual Studio Express 2012 for Web
As #Sound pointed out, you are probably missing the users from the DB that is hosted on Azure. You can access Sql Azure using Sql Management Studio once you open up the firewall through the Azure portal. From there, you can run a script to insert the users, or do it manually through SSMS.
There are many options for migrating data, the above just being a few. You might also look into EF Data Migrations as that might be a good fit as well.

Trying to connect ASP.NET MVC to SQL Server 2008 R2 with possible wrong connection string

Running SQL Server 2008 R2 and ASP.NET MVC 2 web application on the Virtual Server of big german hosting-provider.
I have a problem to connect to the SQL Server.
On localhost this connection string works fine:
#"Data Source=LOCAL-HP;Initial Catalog=OnlineVertrag;Integrated Security=True";
I'm using a similar connection string on the server:
#"Data Source=MYSERVER\SQLEXPRESS;Initial Catalog=OnlineVertrag;Integrated Security=True";
but nothing happens over there.
Here is my project which I am trying to connect: http://www.hotcont.eu/OnlineVertrag/Home
Based on your comments, your SQL instance on the server has a username/password combination. You cannot use the integrated security connection for a SQL Server connection requiring SQL authentication.
Using the login information provided to you by your host, you should update your connection string to the following:
Server=MYSERVER\SQLEXPRESS;Database=OnlineVertrag;User Id=myUsername;
Password=myPassword;
Taken from ConnectionStrings.com
EDIT
Ok - I think I know what you are dealing with now. You have a virutal machine hosted on a large hosting provider -> meaning that you have control over the machine itself (aka Remote Desktop Management or something?)
The SQL connection string that I provided is for use with SQL server accounts -> meaning those that you actually create within SQL server itself. The SQL connection string that you provided uses the current logged in user's user account information from Windows to connect to SQL.
So here is the disconnection between localhost and the virtual server. When you are running on localhost, I am going to assume that you are using the built in web server to Visual Studio or some equivalent. Most often, during debugging, the web application is running under the Logged in user of the machine - aka: you. You have permission to your own SQL database, thus no issue. BUT...when you deploy your web application to an IIS instance, the web application is no longer running as the logged in user, but rather the identity of the application pool that is your app is a member of. Typically this is something like NETWORKSERVICE.
You have three options available to you
Enable and use SQL user accounts for connection from your web application and your SQL server. If you choose to go this route, you will need to use the connection string I provided above.
Login to your SQL server and add the identity of your application pool to the Allowed Users of SQL server and your database.
Change your application pool's identity to an actual user account on the server (BAD IDEA)
Most web applications go with the first option as it allows you do a few things such as create a distinct SQL user for each application that you host and as well as you can explicitly define permissions for the SQL user to each database that it may need access to (for instance, do not allow the SQL user to DROP tables).
EDIT 2
The way you are trying to connect sounds like it should be using the Shared Memory Protocol, but it might be trying to connect over TCP/IP. I forgot this earlier, but most installs of SQL are not setup to listen on the TCP/IP interface on first install. To check your configuration, click the start button (or orb or whatever Microsoft calls that now) -> All Programs -> Microsoft SQL Server 2008 -> Configuration Tools -> SQL Server Configuration Manager. This will open a new window with some options on the left hand side. Click the SQL Server Network Configuration. Ensure that TCP/IP and Shared Memory is set to enabled. If a 64 bit install, you should probably do this for both the SQL Server Network Configuration (32 bit) and the SQL Server Network Configuration
http://msdn.microsoft.com/en-us/library/ms191294.aspx
Try this
Data Source=MYSERVER\SQLEXPRESS;Initial Catalog=OnlineVertrag;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False
I hope this works for you.

Sharepoint Database Access within a domain

I have two servers in a domain. Web Server & Database Server.
I have a number of standard .net websites accessing the SQL Server with no problems, using SQL Username/password combos for each database.
Sharepoint configures the access as Integrated Security=True
When I ran the Config wizard, I 'briefly' saw the Admin top-site.
After a short browse around, I lost the connection. [I touched/changed nothing!!!!]
I now get "Cannot connect to the configuration database."
It seems obvious that the problem is one of access permissions to the database but I can't see it.
The IIS Website uses the Sharepoint AppPool which in turn uses a Domain Account that successfully created the SharePoint_Config Database and & Content databases. They obviously continue to use that account.
The Event Viewer shows multiple instances of:
"Unable to connect to the database SharePoint_Config on [Database Computer]. Check the database connection information and make sure that the database server is running.."
Any suggestions?
This occurs when:
The SQL database or service is not online/running.
Internet Information Services (IIS) is configured to run in IIS 5.0 isolation mode.
The account that is used by application pool does not have the required permissions to the SQL Server database.
Network connectivity has been lost between the Windows SharePoint Services server and the Microsoft SQL Server server.
Check all of those and if all of that is set, check your sql server. Make sure your config database isnt marked as 'suspect' or that something else isnt off. Try resetting your SQL service.
I've also had this happen when an application pool account was changed. Even if the application pool is online, sometimes recycling it does the trick. Alternatively, confirm the application pool account:
Open Server Manager.
Click on Roles.
Choose Web Server (IIS)
Choole IIS.
Open server in the Connections panel.
Choose Application Pools.
For every item in Application Pools, click on it once, and then choose Advanced Settings.
Under Process Model, Identity,
change it, choose "Custom Account".
Enter an account and password for an account with a lot of permissions. I used the Sysadmin.
Restart the Web Server.
Also, 32 or 64 bit? Make sure IIS is running in the right mode, sometimes additional software installs can change things:
First, fix IIS:
\inetpub\AdminScripts\cscript.exe adsutil.vbs set W3SVC/AppPools/Enable32BitAppOnWin64 False
Second, reregister the .Net isapi filters:
\windows\microsoft.net\Framework64\v2.0.50727\aspnet_reg
iis.exe -i
If it is none of the above, have there been any DNS or NETBIOS changes? That is also a common cause.
If nothing else works, simply try to reboot your server.

Resources