Hi, Is it possible to insert a connection string into a web.config file if it isnt there? Would this work? The connection string is for a APS.NET user login and create account database.
A:
Yes it is very possible:
<connectionStrings>
<add name="yourNameHere" connectionString="connectiongStringHere" providerName="nameHere"/>
</connectionStrings>
inside ConfigSections
Eton B.
2010-08-05 16:07:19
Thanks, but in the 'add name="yourNameHere" , what would the name be?
pmoth81
2010-08-05 16:17:58
It's the name you would give to the connection string, to later make reference to it.You could use ConfigurationManager.ConnectionStrings["yourNameHere"].ConnectionString to retrieve it.
Eton B.
2010-08-05 16:30:49
A:
Put a default connectionstring in your web.config and replace the username/password and database name at runtime as desired.
Jeroen
2010-08-05 16:07:57
+1
A:
How do you mean "insert?" If you mean can you manually edit web.config: yes, you can. You'd add an entry for connectionStrings (if there wasn't one) an then a child node for your specific connectionString.
If you mean can you do it in code: theoretically yes. However, it is normally bad practice, and a pain the rear.
AllenG
2010-08-05 16:08:00
If you needed to be able to switch connectionstring at runtime you could chuck it into a database instead of web.config
AndreasKnudsen
2010-08-05 16:59:32