best technique for connection strings in web.config in ASP.NET 2.0

B

Brian Henry

I've never stored a program specific connection string in the web.config
file before, is there any information on how to store it there and access it
from the app and what would be the best way to handle a string like this in
asp.net 2.0? thanks!
 
P

Patrick.O.Ige

Brian you can store it by doing:-
<add key="YourconnectionString"
value="server=yourservername;database=yourdatabase;integrated
security=true;" />
In your apps do:-
SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["YourconnectionString"]);
Hope that helps
Patrick
 
P

PL

Although that still works that is not the ASP.NET 2.0 way of doing it, you store your connectionstrings
in the section:

<connectionStrings>
<add name="dbConnStr"
connectionString="Data Source=yourserver;Initial Catalog=yourdb;Integrated Security=SSPI"/>
</connectionStrings>

and then use:

string sConnStr = ConfigurationManager.ConnectionStrings["MyConnStr"].ConnectionString;

You can also encrypt your connection strings using the commandline aspnet_regiis

PL


Patrick.O.Ige said:
Brian you can store it by doing:-
<add key="YourconnectionString"
value="server=yourservername;database=yourdatabase;integrated
security=true;" />
In your apps do:-
SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["YourconnectionString"]);
Hope that helps
Patrick


Brian Henry said:
I've never stored a program specific connection string in the web.config
file before, is there any information on how to store it there and access it
from the app and what would be the best way to handle a string like this in
asp.net 2.0? thanks!
 
B

Brian Henry

thanks everyone! I knew something changed in 2.0 but wasnt sure, the info
given helps a lot
 
K

Kevin Spencer

Considering the more strict schema of configuration files in the .Net 2.0
framwork, you may find the CollectionStrings element to be your best bet.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top