Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can Web.Config store database connection settings? 1

Status
Not open for further replies.

BiancaJ

Technical User
Nov 4, 2002
51
0
0
GB
At the moment I have my database connection setings (i.e. Userid, password) in Global.asax.

This is a drag as everytime I make a change to the connection string, I have to do a build.

Can I have the connection string in the Web.Config file?

Thanks,

Bianca
 
Yes, that's what I did:

Update your config.web like this:

<configuration>
<appSettings>
<add key=&quot;Conn&quot; value=&quot;data source=ServerName;Initial Catalog=DBName;Integrated Security=SSPI&quot;/>
</appSettings>

And to call it from elsewhere:

Dim conSQL As SqlClient.SqlConnection
Dim comSQL As New SqlClient.SqlCommand()
conSQL = New SqlClient.SqlConnection()

conSQL.ConnectionString = ConfigurationSettings.AppSettings(&quot;Conn&quot;)
conSQL.Open()

Hope it will help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top