none
"The underlying provider failed on Open." when invoking the SaveChanges method

    Question

  • I wanna write a demo about the ado.net entity framework. But i find a strange problem whenever i invoke the saveChanges method.

                using (NorthwindEntities myDb = new NorthwindEntities())
                {
                    Customers customer = new Customers();

                    Random rm = new Random();

                    customer.CustomerID = "A" + rm.Next(9999).ToString();
                    customer.CompanyName = "EntLib.com Forum";
                    customer.Address = "http://www.EntLib.com";

                    myDb.AddToCustomers(customer);

                    int count = myDb.SaveChanges();

                    txtCustomerID.Text = customer.CustomerID;
                }

     

    i just map the Northwind db and insert a recond into the customers table. However, the error "The underlying provider failed on Open."  is thrown. Can anyone help me resolve it? The following is the connectstring.

     

      <connectionStrings>
        <add name="NorthwindEntities" connectionString="metadata=res://*/NorthwindDB.csdl|res://*/NorthwindDB.ssdl|res://*/NorthwindDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=LSMIS006;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>

    Sunday, August 24, 2008 1:51 PM

All replies

  • Hi Michael

     

    Do you have any other code in your project where you are successfully connecting to the database? A query or something?

     

    Is your model in the same project as this code?

     

    That error isn't necessarily related to SaveChanges but just about connecting to the db.

     

    julie

     

    Sunday, August 24, 2008 9:03 PM
  • Hi michael

    I have the same error and iwonder if you have got any solution. But my error is bit different . The error is : "The underlying provider failed on connectionstring".

    I put below my connectionstring.

    Code Snippet

    <connectionStrings>

    <add name="Veto2000Connection" connectionString="metadata=res://*/Veto2000DataModel.csdl|res://*/Veto2000DataModel.ssdl|res://*/Veto2000DataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=BLOCHAOU-FUJI-P\SQLEXPRESS;AttachDbFilename=C:\PDM\PDMVeto2000\PDMVeto2000\PDMVeto2000.mdf;Initial Catalog=PDMVeto2000;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

    </connectionStrings>

     

     

     

    Tuesday, August 26, 2008 4:55 PM
  • Hi,
    I had same problem, and solve adding the Password in my AppConfig:

     <add name="TestEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=destination.server;Initial Catalog=Test;User ID=myuser;Password=mypass;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
     
    I don´t understood why, but works...


    hope this helps


    --
    []´s
    Rafael Izidoro

    Thursday, October 02, 2008 4:57 PM
  • I have mentioned password in connection string. It works most of the times. But sometimes, the same working code starts generating this exception. Its very wierd and I do not know what to do.

    Any suggestions ?

    Jyotsna

    • Proposed as answer by Msahu3 Sunday, December 06, 2009 10:54 AM
    Wednesday, November 25, 2009 6:34 AM
  • Add the same AppConfig Connnectionstring , in the Web Project 's WEB.Config file.

    It worked for me.

    Please let me know if still have the Issue.
    • Proposed as answer by Msahu3 Sunday, December 06, 2009 10:56 AM
    Sunday, December 06, 2009 10:56 AM
  • I am having the same problem.  I outlined the whole thing at http://stackoverflow.com/questions/2158853/entity-framework-the-underlying-provider-failed-on-connectionstring .  It is driving me nuts and is happening at a critical time.

    Any help is appreciated.  And yes, I read everything above this and:
    • Yes, I can connect in other projects.
    • I have the password in the string.
    • I added it to my web.config.
    Since this thread has been alive for over a year I am assuming that there is no answer at this point.
    Keith Barrows
    Friday, January 29, 2010 12:00 AM
  • I had same problem, I found that I was using Distributed TXN, but one of the machine was not configured to enable/authorize MSDTC. I configured and worked fine. Almost I have seen in this kind of exception that the InnerException says appropriate message while debugging.
    Friday, June 04, 2010 9:37 PM
  • Add the same AppConfig Connnectionstring , in the Web Project 's WEB.Config file.

    It worked for me.

    Please let me know if still have the Issue.


    I too had the same issue.  When I look at my InnerException it said that I did not have access to the database.  My problem was that I had changed my DB name half way through.  The problem is not changing the DB name but that I did not change that in my connectionstring in my config file. 

    So I updated the config file in my Model Class Project but did not update it in my Console project that referenced the model.  Hope this helps someone else!


    Fallen
    • Proposed as answer by Ricky Jones Wednesday, July 27, 2011 7:55 PM
    Tuesday, June 22, 2010 6:51 PM
  • Well, that error raises when I was using SaveChanges inside an instance of TransactionScope in the development machine. The workaround for me:
    - Enable Distributed transaction coordinator under the windows firewall->exceptions tab.
    - Enable the Distributed transaction coordinator in the windows services.

    And also, this guide for the production environment: http://technet.microsoft.com/en-us/library/cc753510(WS.10).aspx
    Thursday, November 25, 2010 6:32 AM
  • More than likely the problem is that your credentials on the client end are not getting passed to the SQL part of the service. Or it is your credentials are not valid for that SQL database either. I had the same issue until I put in an SA password on the service side.The part I need to figure out is how to get the credentials passed through correctly with Windows Authentication. The combination that is working for me right now is Windows Authentication on both ends with the connection string with an SA password. I would like it to be Windows Authentication only.

    Wednesday, February 16, 2011 1:17 PM
  • Help please.  I am using the Tailspin Spyworks application as a template.  I am still on xp pro.  I have visual studio 2010.  When I run the application using the developement version of localhost where it assigns a random port, it works fine.  When I bebug using IIS, I constanly get System.Data.EntityException {"The underlying provider failed on Open."}.  Anyone have any ideas.
    Monday, February 21, 2011 7:42 PM
  • Well, that error raises when I was using SaveChanges inside an instance of TransactionScope in the development machine. The workaround for me:
    - Enable Distributed transaction coordinator under the windows firewall->exceptions tab.
    - Enable the Distributed transaction coordinator in the windows services.

    And also, this guide for the production environment: http://technet.microsoft.com/en-us/library/cc753510(WS.10).aspx

    TKs  ric_bolivia !   It worked for me.

    Curious that this is no issue if I use ADO.NET Entity,  but with  Entity Framework "entity framework reverse engineer code first"  (the popup menu at solution exporer)  IT IS AN ISSUE.

    tks again

    • Proposed as answer by JYAZ Thursday, June 06, 2013 10:07 PM
    Saturday, March 10, 2012 11:37 PM
  • I was breaking my head over the exact same problem. I was able to fix it by directly providing the connection string where the connection string name was available in the DBContext class entity framework creates. I will now write a piece of code myself to read it from config and pass it in.

    public TestDBContext()
       : base("Data Source=sqlserver-01;Initial Catalog=TestDB;Integrated Security=True;MultipleActiveResultSets=True")
      {
      }

    Saturday, October 20, 2012 7:11 AM