Groups | Blog | Home
all groups > asp.net > february 2005 >

asp.net : Dynamic Connectionstring in Web.Config ?



karfei00 NO[at]SPAM yahoo-dot-com.no-spam.invalid
2/24/2005 9:39:13 PM
Setting dynamic connectionstring in aspx files is easy, for example :

"server=(localhost);uid=sa;pwd=; databse=" + database

But can i do this in Web.Config? I want to pass the value of the
variable "database" from aspx to Web.Config ad then set the dynamic
connectionstring there. Can i do that ? thanks a lot


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
MasterGaurav
2/24/2005 10:01:01 PM
Make the connect string as:

"server=(localhost); uid=sa; pwd=; database = {0}"

In Application_Load method (in global.asax) or whenever you get the
database name, create an application-scope (or whatever suits you)
variable by formatting the string. Example:

void SomeMethod(string databaseName)
{
string connstr = ConfigurationSettings["connectionString"];
connstr = String.Format(connstr, databaseName);

// now you can scope this connstr to your likes.
}

--
Cheers,
Gaurav Vaish
http://www.mastergaurav.org
http://mastergaurav.blogspot.com
--------------------------------
Kevin
2/25/2005 1:42:58 PM
One of the features of this tool can dynamically set/update the Web.Config's
Key-Value on-fly:
www.aspsimply.com/vbnet/ProTool.aspx

Regards,



[quoted text, click to view]

AddThis Social Bookmark Button