Question about AppSettings?

G

Guest

Hello All!
I'm just trying to set my SQL connection String in the app setting of my
Web Config. I got it to work on one page, but my code is a little diffrent
for another page that has a little more code and stuff goin on.

This is my current connection string..
Protected Const SQL_CONNECTION_STRING As String = _
"Data Source=192.168.100.120,xxxx;Network Library=dbmssocn;Initial
Catalog=mycatalog;User ID=****;Password=*****;"

This is the line of code that I would like to use
Dim myconnection As New
SqlConnection(ConfigurationSettings.AppSettings("ConnString"))

But when I use it, "SQL_Connection_String" is tagged as wrong in a line of
code further down, like...
Dim Sqlconnection1 As New SqlConnection(SQL_CONNECTION_STRING)
I get "Not declared" error.
I also tried it this way,
''' Protected Const SQL_CONNECTION_STRING As String = "MyConnection"

I'm think I'm just not putting it in the right way.

Any advice would be great!!

TIA!!!

Rudy
 
J

Juan T. Llibre

Ty this in web.config:

<configuration>
<appSettings>
<add key="connstring" value="server=Data Source=192.168.100.120,xxxx;Network Library=dbmssocn;Initial Catalog=mycatalog;User ID=****;Password=*****;"/>
</appSettings>
</configuration>

Then, in your aspx file, call it like this :
Dim myConnection as New SqlConnection(ConfigurationSettings.AppSettings("connstring"))



Juan T. Llibre
ASP.NET MVP
===========
 
G

Guest

Hello Juan,
Thanks for the quick response.
I have my code correct in my web config. In my one page, where this does
work, I'm calling up my key from the app settings as
Dim myconnection As New
SqlConnection(ConfigurationSettings.AppSettings("ConnString"))
This works great! It this other line of code that I have that I mentined
earlier,
Protected SQL_CONNECTION_STRING As String = _
'"Data Source=192.168.100.120,xxxx;Network Library=dbmssocn;Initial
Catalog=mycatalog;User ID=xxxx;Password=xxxx;"
that I can't seem to call it the same way. Is it because I'm calling it as a
string?

Rudy
 
G

Guest

Hello All!!

I figured it out. I just didn't put my code in the right combination. All I
had to do to call my connection string from the apps in thw web config was
Protected SQL_CONNECTION_STRING As String =
ConfigurationSettings.AppSettings("ConnString")
Thanks for your help Juan!!

Rudy
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top