473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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!
Nov 19 '05 #1
7 1364
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" <no****@nospam.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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!

Nov 19 '05 #2
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" <na********@hotmail.com> skrev i meddelandet news:eP*************@TK2MSFTNGP15.phx.gbl...
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" <no****@nospam.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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!


Nov 19 '05 #3
I have a related article that talks about some of the new config
features in 2.0. http://odetocode.com/Articles/418.aspx

As others pointed out, the biggest difference is a dedicated
<connectionStrings> section and the WebConfigurationManager class.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 6 Nov 2005 16:31:54 -0500, "Brian Henry" <no****@nospam.com>
wrote:
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!


Nov 19 '05 #4
thanks everyone! I knew something changed in 2.0 but wasnt sure, the info
given helps a lot

"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:p3********************************@4ax.com...
I have a related article that talks about some of the new config
features in 2.0. http://odetocode.com/Articles/418.aspx

As others pointed out, the biggest difference is a dedicated
<connectionStrings> section and the WebConfigurationManager class.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 6 Nov 2005 16:31:54 -0500, "Brian Henry" <no****@nospam.com>
wrote:
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!

Nov 19 '05 #5
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.

"Brian Henry" <no****@nospam.com> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
thanks everyone! I knew something changed in 2.0 but wasnt sure, the info
given helps a lot

"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:p3********************************@4ax.com...
I have a related article that talks about some of the new config
features in 2.0. http://odetocode.com/Articles/418.aspx

As others pointed out, the biggest difference is a dedicated
<connectionStrings> section and the WebConfigurationManager class.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 6 Nov 2005 16:31:54 -0500, "Brian Henry" <no****@nospam.com>
wrote:
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!


Nov 19 '05 #6
that is exactly what i converted my existing ones to

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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.

"Brian Henry" <no****@nospam.com> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
thanks everyone! I knew something changed in 2.0 but wasnt sure, the info
given helps a lot

"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:p3********************************@4ax.com...
I have a related article that talks about some of the new config
features in 2.0. http://odetocode.com/Articles/418.aspx

As others pointed out, the biggest difference is a dedicated
<connectionStrings> section and the WebConfigurationManager class.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 6 Nov 2005 16:31:54 -0500, "Brian Henry" <no****@nospam.com>
wrote:

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!



Nov 19 '05 #7
Hey Brian,

You should look at:
http://msdn.microsoft.com/library/de...aght000005.asp

If this is your server I would suggest looking into how to use RSA or DPAPI
to encrypt the info.
--
kr**@n-sv.com.<Remove This Before Emailing>

Network & Software Integration
www.n-sv.com

"Helping put the pieces of your IT puzzle together"
"Brian Henry" wrote:
that is exactly what i converted my existing ones to

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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.

"Brian Henry" <no****@nospam.com> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
thanks everyone! I knew something changed in 2.0 but wasnt sure, the info
given helps a lot

"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:p3********************************@4ax.com...
I have a related article that talks about some of the new config
features in 2.0. http://odetocode.com/Articles/418.aspx

As others pointed out, the biggest difference is a dedicated
<connectionStrings> section and the WebConfigurationManager class.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 6 Nov 2005 16:31:54 -0500, "Brian Henry" <no****@nospam.com>
wrote:

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



Dec 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
1
by: stewart | last post by:
I've got the standard SqlCacheDependency working just fine , ie. I've defined (and encrypted) the connectionStrings section in the web.config, and I've also defined an an sqlCacheDependency in the...
14
by: WebMatrix | last post by:
Hello, I have developed a web application that connects to 2 different database servers. The connection strings with db username + password are stored in web.config file. After a code review,...
2
by: dasomerville | last post by:
We have different settings for our development, stage and production environments. For example, our development environment connection strings point to development database instances, stage...
7
by: Steve | last post by:
I am building an object library for tables in a database. What is the best practice for creating objects like this? For example, say I have the following tables in my database: User: - Id -...
3
by: Nemisis | last post by:
Guys, I would like to write a error handler, or something, that will allow me to write to a database when an error occurs on my site. I am trying to implement this in the global.asax file a the...
9
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a question about storing the connection strings to the database in a config file or database. My manager wants me to store all the connection strings in a database, but I...
2
by: Johnson | last post by:
I'm trying to fix a "sub optimal" situation with respect to connection string management. Your thoughtful responses will be appreciated. I just started with a new client who has a bunch of legacy...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.