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.