0

I am running my ASP.NET application in IIS as a site. When I go to login to the website through the SQL Server database, it returns an error. I can run the web application through Visual Studio using IIS Express without any issues.

I have looked at tutorials saying to check my connection string.

<connectionStrings>
    <add name="DefaultConnection" 
         connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-VideoStore-20190515111127.mdf;Initial Catalog=aspnet-VideoStore-20190515111127;Integrated Security=True" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

This is the error:

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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.)

I use the Server Explorer to look at the Data Connections>Default Connection (Video Store) to see the database in Visual Studio. Can someone point me in the right direction?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

1

The user that the application is running as under IIS does not have permission to the database you have specified in your connection string. When you are running the site under VS the user is running as your local windows user. When you deploy to IIS it is running as the application pool user. Check what user this is running under by going to IIS > Sites > Right Click The Site > Manage WebSite > Advanced Settings. That is the user it is running as and that user may need to have SQL access.

Jake Steffen
  • 415
  • 2
  • 11
0

Firstly you have to confirm both IIS and Sql server are running in the same machine or not, if running in the same you need to change the connection string related to local DB or windows authendication.

if not running in the same machine use like

<add name="yourconnectinstringName" connectionString="Data Source= DatabaseServerName; Integrated Security=true;Initial Catalog= YourDatabaseName; uid=YourUserName; Password=yourpassword; " providerName="System.Data.SqlClient" /> 

and recheck the DB name you enterd and Server details.

I hope connection string you provided is invalid,sorry if i am wrong.

still your facing problem please go through Connecting to local SQL Server database using C#