C# – Assign connection string to table adapter from session


My application is already developed and now we are going to change the connection string whatever stored in the session object (Bcoz of Distributed Database Management System (DDBMS))

Problem is here…..

In that application There are so many **ObjectDataSource** which are

initialize with the using .XSD
file. which is related to the
TableAdapter and in which connection string of TableAdapter
is assign from the Web.Config File.
Now How to change the connection
string to whatever stored in session

Thanks in advance.

Best Solution

To change the connection of an XSD at runtime you'll need to set the ConnectionModifier property of the table adapter to Public. If they're created by the "wizard" they will be set to Friend/Internal (VB/C#) by default.

I had trouble finding the ConnectionModifier property (it's not listed in my vs2005 documentation)! If you click the lower area of the XSD (where the queries are) then it should be visible in the properties window to change.

Then you can set the Connection property (it takes an object not a string) where ever you declare your table adapter.