Reputation: 4503
I have a sample .NET Core 2.1 application which is using IIS Express and a LocalDB, but whenever I run the WebAPI application I get the below error:
System.Data.SqlClient.SqlException (0x80131904): 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 get a local application data path. Most probably a user profile is not loaded. If LocalDB is executed under IIS, make sure that profile loading is enabled for the current user.
My connection string is:
"ConnectionStrings": {
"DefaultConnection": "Data Source=(localdb)\\MSSQLLocalDB,1433;AttachDbFilename=C:\\temp\\gitprojects\\TokenAuthAPI\\TokenAuthAPI\\TokenAuth.mdf;Integrated Security=True"
}
I initially did not have the .mdf
path or, 1433 but I added those after checking online, but still same error.
In Visual Studio under SQL Server Object Explorer I made the database and see it, also when I run the command (in command prompt) SQLLocalDb info MSSQLLocalDB I see it running.
If I right click and check the properties of the database in SQL Server Object Explorer and use that connection string, I get the same error:
Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=TokenAuth;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
Is this related to IIS permissions?
Upvotes: 2
Views: 4620
Reputation: 519
For me changing the AppPool user to LocalSystem worked perfect.
Source: Add IIS 7 AppPool Identities as SQL Server Logons
Upvotes: 1
Reputation: 170
You must add a pool As long as the AppPool name actually exists, the login should now be created.
How I've gotten it to work is:
Or
CREATE LOGIN [IIS APPPOOL\MyAppPool] FROM WINDOWS;
CREATE USER MyAppPoolUser FOR LOGIN [IIS APPPOOL\MyAppPool];
Upvotes: 5