Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good afternoon, I have encountered a problem to choose from two connection strings using C# and Linq to Entities. Currently I have two connection strings which are:

XML
<add name="GameHutDBEntities1" connectionString="metadata=res://*/GameHutModel.csdl|res://*/GameHutModel.ssdl|res://*/GameHutModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=EMMANUEL-PC\SQLEXPRESS;Initial Catalog=GameHutDB;user id=GameHutAdmin; password=123;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
    <add name="GameHutDBEntities2" connectionString="metadata=res://*/GameHutModel.csdl|res://*/GameHutModel.ssdl|res://*/GameHutModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=EMMANUEL-PC\SQLEXPRESS;Initial Catalog=GameHutDB;user id=test; password=1234;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />


I have two roles which are Admin and Clerk. How can I allow the admin to login with the first connection string and the clerk will login with the second connection string?

Thanks!!
Posted

The ObjectContext[^] object has a overridden constructor that takes the connection string name. You would just need to use it within your code to construct the context based on the user role.
 
Share this answer
 
v2
Comments
NandaKumer 25-Dec-11 10:53am    
good one
 
Share this answer
 
Comments
Monjurul Habib 25-Dec-11 16:12pm    
nice link , sure 5!
I have improved my previous answer but still the status "Deleted", anyway i am re-posting my answer:

Navigate experts answers:

EF and change of server (connection string)
Determine connection string based on environment, while using Entity Framework
Get Entity Framework connection string from alternate location?

NB: If anyone needs to delete the answer again, let me know the reason first, so that we can go through a good discussion.
 
Share this answer
 
v2

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