Click here to Skip to main content
14,825,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all i have connection with one server...in certain condition i want t0 change server so need to change connection string by closing first one and after performing task of another server again close that one and start old one ///


Do you have any better approach to do this
Posted

You can certainly open up multiple simultaneous connections without first closing existing connections down.
   
This Code may help u

C#
var settings = ConfigurationManager.ConnectionStrings[ 0 ];
var fi = typeof(ConfigurationElement).GetField(
              "_bReadOnly", 
              BindingFlags.Instance | BindingFlags.NonPublic);
fi.SetValue(settings, false);
settings.ConnectionString = "Data Source=Something";
   
v2
Comments
Wendelius 21-Dec-11 15:58pm
   
Pre tags added to enhance readability

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