ihorko
ihorko

Reputation: 6945

Build Entity connection string from ADO.NET

In my web site I have regular ADO.NET connection string like: ,

now Entity Framework added it's own connection string to same database.

How is it possible to use only one ADO.NET connection string and build Entity Connection string in runtime?

Upvotes: 1

Views: 1033

Answers (1)

COLD TOLD
COLD TOLD

Reputation: 13599

you can use EntityConnectionStringBuilder to generate connection string at runtime dynamically at runtime but you still need metada for this

EntityConnectionStringBuilder entityBuilder =
    new EntityConnectionStringBuilder();
    //Set the provider name.
    entityBuilder.Provider = providerName;

    // Set the provider-specific connection string.
    entityBuilder.ProviderConnectionString = providerString;

    // Set the Metadata location.
    entityBuilder.Metadata = @"res://*/AdventureWorksModel.csdl|
                                res://*/AdventureWorksModel.ssdl|
                                res://*/AdventureWorksModel.msl";
using (EntityConnection conn =
    new EntityConnection(entityBuilder.ToString()))
{
    conn.Open();
    Console.WriteLine("Just testing the connection.");
    conn.Close();
}

Upvotes: 3

Related Questions