Deploy ASP .NET MVC application using LocalDB to local IIS

2017/10/18 05:49
When ASP application is published to IIS using LocalDB accessing the database may result in the following error:

Server Error in '/Application_Name' Application.
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.)

An easy solution to fix this error is to set IIS Application pool Process Model Identity to Local System.

Do not forget also to copy the database to appropriate directory on the same host where IIS is running and to set corresponding path in project Build -> Publish -> Settings -> ApplicationDBContext (DefaultConnection). Use "..." browse button to easy set all database connection properties.

iis application pool process model Identity