Entity Framework the Underlying Provider Failed on Open

MSSQL Error 'The underlying provider failed on Open'

I had this error and found a few solutions:

Looking at your connection string, it looks valid. I found this blog post, the problem here is that they were using Integrated Security. If you are running on IIS, your IIS user needs access to the database.

If you are using Entity Framework with Transactions, Entity Framework automatically opens and closes a connection with each database call. So when using transactions, you are attempting to spread a transaction out over multiple connections. This elevates to MSDTC.

(See this reference for more information.)

Changing my code to the following fixed it:

using (DatabaseEntities context = new DatabaseEntities())
{
context.Connection.Open();
// the rest
}

Entity Framework The underlying provider failed on Open

Seems like a connection issue. You can use the Data link properties to find if the connection is fine. Do the following:

  1. Create a blank notepad and rename it to "X.UDL"
  2. Double click to open it
  3. Under connections tab choose the server name/enter the name
    use the correct credentials and DB
  4. Click OK to save it.

Now open the file in Notepad and compare the connection string properties.

The underlying provider failed on Open iis

Based on that connection string, the identity trying to connect to your SQL instance is the user account that is specified in your application's IIS app pool (usually iis apppool\defaultapppool). You'll either need to;

  • allow this account to access the SQL database
  • put the necessary credentials for a SQL account into the connection string
  • set the windows account details on the app pool in order for the application to connect.

What's happening is that when you're debugging, the account used to connect via Integrated Security=True is the currently logged in user account - which is likely set up to allow you to connect to the database, especially if you've installed SQL Server during the setup of your machine (it's the default SQL Server setup config to add the current user). However IIS needs a specific account to run under which isn't the currently logged in user - hence the need for the options above.

MSSQL Error 'The underlying provider failed on Open' using WCF & EntityFramework

Looking at your connection string, it looks valid. I found this blog post, the problem here is that they were using Integrated Security. If you are running on IIS, your IIS user needs access to the database.

If you are using Entity Framework with Transactions, Entity Framework automatically opens and closes a connection with each database call. So when using transactions, you are attempting to spread a transaction out over multiple connections. This elevates to MSDTC.

(See this reference for more information.)

Please read this article:
MSSQL Error 'The underlying provider failed on Open'

Entity Framework The underlying provider failed on Open

Error: The underlying provider failed on Open. How to resolve it?

Window Service In C# - The underlying provider failed on Open

Your service is running as the System user which doesn't (and shouldn't) have permission to log on to the database.

Either create a SQL login and add its credentials to the connection string or run your service as a user that has permissions to log in to the database.

In the service properties -> Log On tab, change the account:
Sample Image

Entity Framework Exception The underlying provider failed on Open

Usually, when working with Entity Framework you'll need to enable the multiple active result sets option in your connection string by setting MultipleActiveResultSets to true as follows.

<add name="conn" 
connectionString="
Data Source=.\;
Initial Catalog=TDB;
UID=admin123;
PWD=123;
MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />

Verify that it solves your problem.



Related Topics



Leave a reply



Submit