MSSQL Error 'The underlying provider failed on Open'

前端 未结 30 2547
时光取名叫无心
时光取名叫无心 2020-11-22 09:51

I was using an .mdf for connecting to a database and entityClient. Now I want to change the connection string so that there will be no

相关标签:
30条回答
  • 2020-11-22 10:18

    Defining a new Windows Firewall rule for SQL Server (and for port 1433) on the server machine solves this error (if your servername, user login name or password is not wrong in your connection string...).

    0 讨论(0)
  • 2020-11-22 10:20

    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
    }
    
    0 讨论(0)
  • 2020-11-22 10:20

    I had the same problem but what worked for me was removing this from the Connection String:

    persist security info=True

    0 讨论(0)
  • 2020-11-22 10:23

    I had a similar error with the inner exception as below:

    operation is not valid for the state of the transaction

    I could resolve it by enabling DTC security settings.

    Go To Properties of DTC, under Security Tab, check the below

    • Network DTC Access
    • Allow RemoteClients
    • Transaction Manager Communication
    • Allow Inbound
    • Allow Outbound
    0 讨论(0)
  • 2020-11-22 10:24

    I was searching all over the web for this problem. I had the wrong name in the connection string, please check you connection string in web.config. I had name="AppTest" but it should have been name="App".

    In my AppTestContext.cs file I had:

    public AppTestContext() : this("App") { }
    

    Wrong connection string:

    <add connectionString="Data Source=127.0.0.1;Initial Catalog=AppTest;Integrated Security=SSPI;MultipleActiveResultSets=True" name="AppTest" providerName="System.Data.SqlClient" />
    

    Right connection string:

    <add connectionString="Data Source=127.0.0.1;Initial Catalog=AppTest;Integrated Security=SSPI;MultipleActiveResultSets=True" name="App" providerName="System.Data.SqlClient" />
    
    0 讨论(0)
  • 2020-11-22 10:25

    If you happen to get this error on an ASP.NET web application, in addition to other things mentioned check the following:

    1. Database User Security Permissions (which users are allowed access to your database.
    2. Check your application pool in IIS and make sure it's the correct one that is allowed access to your database.
    0 讨论(0)
提交回复
热议问题