none
Creating a Entity Connection String RRS feed

  • Question

  • I am having trouble passing in a connection string to the entity...

    The following is the connection string that Model builder made and it works if I use this as a default:

     <add name="ETRACS_Entities" connectionString="
          metadata=res://*/ETracs.csdl|res://*/ETracs.ssdl|res://*/ETracs.msl;
         provider=System.Data.SqlClient;
        provider connection string=&quot;Data Source=TBSxxxx\TBSSQLDEVSRV;
                                         Initial Catalog=ETRACS_dev;
                                         Integrated Security=True;
                                         MultipleActiveResultSets=True;
                                         Application Name=EntityFramework&quot;"
        providerName="System.Data.EntityClient" />

    Using the MSDN article on "How to build a connection string I have tried all sorts of things...

    I think my problem is in the dataSource Name....In the MSDN article it was a simple server name

    Mine the more complicated name....and I can't change this as it is an existing database....

    Here is one thing I have tried:

    string providerName = "System.Data.SqlClient";

    string serverName = "TBSxxxx\\TBSSSQLDEVSRV";    ///note the escaped backslash...

                                                                                      ///I think this may be the problem...

    string databaseName = "ETRACS_dev";

    SqlConnectionStringBuildr sqlBuilder = new SqlConnectionStringBuilder ();

    sqlBuilder.DataSource = serverName;

    sqlBuilder.InitialCatalog = databaseName;

    sqlBuilder.IntegreatedSecurity = true;

    string providerString = sqlBuilder.ToString();

    EntityConnectionStringBuildr enityBuilder = new EntityConnectionStringBuilder();

    entityBuilder.Provider = providerstring;

    entityBuilder.MetaData = "res://*/ETracs.csdl|res://ETracs.ssdl|res://*/ETracs.msl";

    EntityConnection connection = new EntityConnection(entityBuilder.ToString());

    using (ETRACS_Entities _entities = new ETRACS_Entities (connection))

    {

    The exception I keep getting is "ex.Message = "The specified store provider cannot be found in the configuration, or is not valid."

    Wednesday, October 10, 2012 9:39 PM

Answers

  • Hi,

    What if you just write the connection string you generated so that you can compare visually with the one you previously had ? This way you should be able to find out easily the issue by yourself.

    It seems to me it could be some kind of confusion between "provider", "provider connection string" and "providerName" ?


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    • Marked as answer by bcsmith1001 Thursday, October 11, 2012 9:25 PM
    Thursday, October 11, 2012 12:20 PM

All replies

  • Hi,

    What if you just write the connection string you generated so that you can compare visually with the one you previously had ? This way you should be able to find out easily the issue by yourself.

    It seems to me it could be some kind of confusion between "provider", "provider connection string" and "providerName" ?


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    • Marked as answer by bcsmith1001 Thursday, October 11, 2012 9:25 PM
    Thursday, October 11, 2012 12:20 PM
  • Thanks for the help.....I got it working...

    I had to change the make the following change:

    entityBuilder.Provider = sqlBuilder.ToString() + "providerName=\"System.Data.EntityClient\"";

    I found this nowhere in the documentation....but this makes it work

    Thursday, October 11, 2012 9:27 PM
  • I spoke too soon...This still gives an error....but as Practice pointed out .... I am sure the cause is ProviderName not being set to System.Data.EntityClient..... I am just not sure how to pass it...I am still working on this.... any one have suggestions"?
    Thursday, October 11, 2012 9:33 PM
  • Ok....I have truly found the problem this time.....It was with a confusion on my part between the Provider and the ProviderConnectionString

    This code works....not the connectionString is the sql connection string that I getting from an app.config file

            EntityConnectionStringBuilder _entityBuilder = new EntityConnectionStringBuilder();

                     _entityBuilder.Provider = "System.Data.SqlClient";
                     _entityBuilder.Metadata = "res://*/ETracs.csdl|res://*/ETracs.ssdl|res://*/ETracs.msl";
                     _entityBuilder.ProviderConnectionString = _session.ConnectionString.ToString();

                    EntityConnection entityConnection = new EntityConnection(_entityBuilder.ToString());

             
                    using (ETRACS_Entities _entities = new ETRACS_Entities(entityConnection))

    Thursday, October 11, 2012 10:12 PM