Dynamically Changing connection string in LINQ to SQL data context not working
-
Thursday, January 10, 2013 7:41 PMDataContext context = new DataContext("portalConnectionString-Prod");
context = new DataContext("portalConnectionString-Test");
Is not working Why?
All Replies
-
Thursday, January 10, 2013 9:25 PM
Hi erchowdary;
Please try it like this. You will need to add a reference to the dll file System.configuration.dll and the using statement:
using System.Configuration;string connStr = ConfigurationManager.ConnectionStrings["portalConnectionString-Prod"].ConnectionString; DataContext context = new DataContext(connStr);
Fernando (MCSD)
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".- Proposed As Answer by Shyam Kr Friday, January 11, 2013 8:09 AM
- Marked As Answer by Alexander SunModerator Wednesday, January 30, 2013 7:58 AM
-
Friday, January 11, 2013 1:00 PM
When you passed portalConnectionString-Test as a paramtere to data context, it considered this string as a connection string.
The problem why your DataContext didn't work is that it recieved incorrect string as a connection string. Pass the correct connection string as a value and everything will work fine.
Please Mark as Reply and Vote as Helpful if I helped.
Also please visit my blog http://msguy.net/

