1

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?

2
  • I belive entity connection string adds metadata to connection string therefore not sure if you can use ADO.NET as Entity Connection string Commented Dec 2, 2012 at 23:04
  • I need take data from ADO.NET and bind Entity connection string, based on ADO.NET Commented Dec 2, 2012 at 23:16

1 Answer 1

3

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();
}
Sign up to request clarification or add additional context in comments.

2 Comments

How can I build this Entity connection string based on ADO.NET connection string?
the connection string is still just a connection string you just need to have Provider, ProviderConnectionString like user info and so on and Metadata you can get by manually creating EF connection string and the copy that metadata to you entityBuilder.Metadata at runtime

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.