Changing the DataSource of a LINQ DataContext dynamically
-
Hello, I have created an application that accesses an SQL database via LINQ. I designed the DataContext via the VS designer (DataContext1.dbml), and this generated all the XML etc. This application will run on several servers and so I need to have a method which changes the DataSource (eg. the Connection String) of the DataContext to the relavent Server. Is there any way of changing the Data Source / Connection String programmatically? The only way I can think of is to programmatically open the XML config files and change the connection string, before declaring the DataContext and running queries on it. The problem with this is that I'll be compiling the code into a DLL and the settings don't come in seperate files it seems, they're embedded in the DLL. Thanks, Conor.
-
Hello, I have created an application that accesses an SQL database via LINQ. I designed the DataContext via the VS designer (DataContext1.dbml), and this generated all the XML etc. This application will run on several servers and so I need to have a method which changes the DataSource (eg. the Connection String) of the DataContext to the relavent Server. Is there any way of changing the Data Source / Connection String programmatically? The only way I can think of is to programmatically open the XML config files and change the connection string, before declaring the DataContext and running queries on it. The problem with this is that I'll be compiling the code into a DLL and the settings don't come in seperate files it seems, they're embedded in the DLL. Thanks, Conor.
Datacontext constructor having option to pass connectionstring. this is one way. qryGenDataContext qryGen = new qryGenDataContext(connectionstring);
Have A Nice Day! Murali.M Blog