473,387 Members | 1,834 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,387 software developers and data experts.

Moving connection strings to web.config file

I've heard talk of being able to move all sql connection strings to the
web.config file and simply referencing them as opposed to inputting the
string everytime you need to use it.

Can someone give me an example of this please?

Nov 18 '05 #1
6 1108
<configuration>
<appSettings>
<add key="ConnectionString" value="SERVER=sql;DATABASE=myDB;Integrated
Security=SSPI" />
</appSettings>
...
</configuration>

ConfigurationSettings.AppSettings("ConnectionStrin g")

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:RJ*********************@news-text.cableinet.net...
I've heard talk of being able to move all sql connection strings to the
web.config file and simply referencing them as opposed to inputting the
string everytime you need to use it.

Can someone give me an example of this please?

Nov 18 '05 #2
Appreciated Michael, thanks

"Michael Ramey" <raterus@localhost> wrote in message
news:Oz**************@TK2MSFTNGP11.phx.gbl...
<configuration>
<appSettings>
<add key="ConnectionString" value="SERVER=sql;DATABASE=myDB;Integrated
Security=SSPI" />
</appSettings>
...
</configuration>

ConfigurationSettings.AppSettings("ConnectionStrin g")

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:RJ*********************@news-text.cableinet.net...
I've heard talk of being able to move all sql connection strings to the
web.config file and simply referencing them as opposed to inputting the
string everytime you need to use it.

Can someone give me an example of this please?


Nov 18 '05 #3
Actually Michael, I've just tried this and it's saying the Configuration
namespace could not be found

Any ideas?

"Michael Ramey" <raterus@localhost> wrote in message
news:Oz**************@TK2MSFTNGP11.phx.gbl...
<configuration>
<appSettings>
<add key="ConnectionString" value="SERVER=sql;DATABASE=myDB;Integrated
Security=SSPI" />
</appSettings>
...
</configuration>

ConfigurationSettings.AppSettings("ConnectionStrin g")

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:RJ*********************@news-text.cableinet.net...
I've heard talk of being able to move all sql connection strings to the
web.config file and simply referencing them as opposed to inputting the
string everytime you need to use it.

Can someone give me an example of this please?


Nov 18 '05 #4
Perhaps try this,

System.Configuration.ConfigurationSettings.AppSett ings("ConnectionString")

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:a%*********************@news-text.cableinet.net...
Actually Michael, I've just tried this and it's saying the Configuration
namespace could not be found

Any ideas?

"Michael Ramey" <raterus@localhost> wrote in message
news:Oz**************@TK2MSFTNGP11.phx.gbl...
<configuration>
<appSettings>
<add key="ConnectionString" value="SERVER=sql;DATABASE=myDB;Integrated
Security=SSPI" />
</appSettings>
...
</configuration>

ConfigurationSettings.AppSettings("ConnectionStrin g")

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:RJ*********************@news-text.cableinet.net...
I've heard talk of being able to move all sql connection strings to the web.config file and simply referencing them as opposed to inputting the string everytime you need to use it.

Can someone give me an example of this please?



Nov 18 '05 #5
Ended up with this working
System.Configuration.ConfigurationSettings.AppSett ings.Get("ConnectionString
")

Thanks for your input

"Michael Ramey" <raterus@localhost> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Perhaps try this,

System.Configuration.ConfigurationSettings.AppSett ings("ConnectionString")

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:a%*********************@news-text.cableinet.net...
Actually Michael, I've just tried this and it's saying the Configuration
namespace could not be found

Any ideas?

"Michael Ramey" <raterus@localhost> wrote in message
news:Oz**************@TK2MSFTNGP11.phx.gbl...
<configuration>
<appSettings>
<add key="ConnectionString" value="SERVER=sql;DATABASE=myDB;Integrated Security=SSPI" />
</appSettings>
...
</configuration>

ConfigurationSettings.AppSettings("ConnectionStrin g")

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:RJ*********************@news-text.cableinet.net...
> I've heard talk of being able to move all sql connection strings to the > web.config file and simply referencing them as opposed to inputting the > string everytime you need to use it.
>
> Can someone give me an example of this please?
>
>
>



Nov 18 '05 #6
Just a suggestion, but if you use System.Configuration you'll won't have to
fully qualify it (ConfigurationSettings is really long so it's well worth it
;-)
"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:Bd*********************@news-text.cableinet.net...
Ended up with this working
System.Configuration.ConfigurationSettings.AppSett ings.Get("ConnectionString ")

Thanks for your input

"Michael Ramey" <raterus@localhost> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Perhaps try this,

System.Configuration.ConfigurationSettings.AppSett ings("ConnectionString")

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:a%*********************@news-text.cableinet.net...
Actually Michael, I've just tried this and it's saying the Configuration namespace could not be found

Any ideas?

"Michael Ramey" <raterus@localhost> wrote in message
news:Oz**************@TK2MSFTNGP11.phx.gbl...
> <configuration>
> <appSettings>
> <add key="ConnectionString" value="SERVER=sql;DATABASE=myDB;Integrated > Security=SSPI" />
> </appSettings>
> ...
> </configuration>
>
> ConfigurationSettings.AppSettings("ConnectionStrin g")
>
> "Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
> news:RJ*********************@news-text.cableinet.net...
> > I've heard talk of being able to move all sql connection strings

to the
> > web.config file and simply referencing them as opposed to
inputting the
> > string everytime you need to use it.
> >
> > Can someone give me an example of this please?
> >
> >
> >
>
>



Nov 18 '05 #7

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

Similar topics

7
by: Gary Brizard | last post by:
OK. For an n-tier architecture, where is the best place to store the connection string for the DA layer? I don't want to use the reg. Can't use a app.config for a dll. For other projects I...
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,...
4
by: Dave | last post by:
We store all of our connection strings in the root web.config. I have a connection string called connectionString1 stored in the web.config file at wwwroot. I can get to this through code no...
4
by: Matt Colegrove | last post by:
I'm working on a web app that is published to a hosting service. I'm developing it on my local PC with VS 2005 and SQL Express. The hosting service DB is SQL Server 2000. I have two...
37
by: sam44 | last post by:
Hi, At startup the user log on and chooses the name of a client from a dropdownlist, which then changes dynamically the connection string (the name of the client indicates which database to use)....
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.