Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a data class library that contains multiple edmx files.

Each edmx file references a different database therefore; I have multiple connection strings. How do I get my context to use the appropriate connection string. E.g.: When I make a call to the second edmx model.

I get an error presumably, because the incorrect connection string was chosen. I found the "EntityConnectionStringBuilder" but, not sure how to apply it.

Any suggestions.
Posted
Updated 3-Dec-13 5:05am
v2

I believe you would just give it the name of the connection string in your app/web.config file.
using (var context = new MyDbContext("connectionStringName"))
{
    ....
}
 
Share this answer
 
If i'm not wrong, you can set mulitiple connection strings in a config file. Have a look here: Entity Framework - Config File Settings[^] and here: Entity Framework - Connections and Models[^]

Example:
HTML
<connectionstrings>
  <add name="BlogContext">
        providerName="System.Data.SqlClient" 
        connectionString="Server=.\SQLEXPRESS;Database=Blogging;Integrated Security=True;"/>
  <!-- here add another connection string -->
</add></connectionstrings>


How to use it? Creating new ObjectContext[] initializes a new instance of the ObjectContext class with the given connection string and default entity container name.

Similar subjects:
How to: Read Connection Strings from the Web.config File[]
Connection Strings and Configuration Files[]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900