I have a Web API hosted on IIS.
In one environment (Windows Server 2012 R2 and SQL Server 2008 R2), the Web API can access the SQL Server database on the same machine.
But in another environment (Windows Server 2008 R2 and SQL Server 2008 R2), I get this exception
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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)
Why it is complaining about local database runtime installation
and SQL Server Express - I have Microsoft SQL Server Standard (64-bit) installed. I suppose IIS doesn't see SQL Server and so expects that there should be SQL Server Express?
When I debug this API on my development machine, then it can access that SQL Server, so connection data is not wrong.
Had a though that might be IIS is executing in different security context than SQL Server
I checked SQL Server Configuration manager and set there Log on as NT Authority\NetworkService
.
And did same in IIS:
Application pool (*entity to which my API is assigned*) -> Advanced settings -> Process Model -> Identity = NetworkService,
and added NT AUTHORITY\NETWORK SERVICE
login to SQL Server and user for the database I need to access from the Web API, but that didn't help.
Why is my code trying to access a local database, if connection string is to a regular SQL Server database?
Data Source=ip-address;Initial Catalog=database;PersistSecurityInfo=True;User ID=sa;Password=...;
From suggestions I've found there were
About accept remote connections: I've checked - database engine is configured to accept remote connections (I wouldn't be able to connect to it from my development machine then)
About firewall exception: I guess that one also is fine since I can access DB from my dev machine
Enable TCP/IP in SQL server configuration; checked - it is enabled
Checked solutions, ideas from here