0

I write a small ASP.NET web application with a controller that can access to my local db to retrive informations. When I start the application from visual studio everything works fine, but when I publish the application to IIS I get this error:

"An error has occurred.","exceptionMessage":"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."

I can't understand why the application works from visual studio but fails after the publish. My connection strings (automatically generated when I create the controller with EntityFramework) are :

<connectionStrings>
<add name="ToDoContext" connectionString="Data Source=(localdb)\MSSQLLocalDB; Initial Catalog=ToDoContext-20190205170505; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|ToDoContext-20190205170505.mdf"
  providerName="System.Data.SqlClient" />

I noticed that when I run the application form VS in the Url there is the port number, meanwhile from IIS there isn't (I don't know if this fact could have any impact). Any suggestions? Thank you.

2 Answers 2

4

This connection string is pointing to an instance of LocalDb. It is highly unlikely that you have this installed on the server, hence getting the connection error.

You need to find out what SQL server instances are available to your IIS application. In a staging or QA environment it might just be localhost but in production it is likely to be separate server.

It is also unlikely that Integrated Security will work (and probably shouldn't be made to work). You need to obtain a username and password from the DBA and use that.

Sign up to request clarification or add additional context in comments.

1 Comment

I create a new sql user with password and it works. Thank you.
0

Because you are using integrated security, make sure the applicationpoolidentity used by IIS is setup for SQL Server as per here: https://blogs.msdn.microsoft.com/ericparvin/2015/04/14/how-to-add-the-applicationpoolidentity-to-a-sql-server-login/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.