Dynamic Connectionstring in Web.Config ?

S

summer00

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
 
K

Kevin

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,



summer00 said:
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
 
M

MasterGaurav

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
--------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top