Programatically switch database connection string?
Posted: Tue 25 Jan 2011 03:52
I have the same database schema on several physical MySql databases, because my host has a 1GB limit on each one.
I'd like to use the same Linq Entity Model (lqml) for each physical database, and just switch the database connection based on the user.
I have tried changing the connection string using MyDataContext context = new MyDataContext("new connection string");
I have tried interrupting the creation of the data context with extension methods on OnCreated(), by changing Connection.ConnectionString = "new connection string";
In both cases I get an error reading from the database, such as "SELECT command denied to user .....". I believe the Database name is embedded in the model, and so even though I changed the connection string it is still trying to access the original database name.
Is there something I can do different, to allow me to change databases but use the same model? Maybe a parameter in the model itself?
Thanks!
-Doc
I'd like to use the same Linq Entity Model (lqml) for each physical database, and just switch the database connection based on the user.
I have tried changing the connection string using MyDataContext context = new MyDataContext("new connection string");
I have tried interrupting the creation of the data context with extension methods on OnCreated(), by changing Connection.ConnectionString = "new connection string";
In both cases I get an error reading from the database, such as "SELECT command denied to user .....". I believe the Database name is embedded in the model, and so even though I changed the connection string it is still trying to access the original database name.
Is there something I can do different, to allow me to change databases but use the same model? Maybe a parameter in the model itself?
Thanks!
-Doc