473,503 Members | 12,791 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about AppSettings?

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("C onnString"))

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

Nov 19 '05 #1
3 1479
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("c onnstring"))

Juan T. Llibre
ASP.NET MVP
===========
"Rudy" <Ru**@discussions.microsoft.com> wrote in message news:BD**********************************@microsof t.com...
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("C onnString"))

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




Nov 19 '05 #2
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("C onnString"))
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
"Juan T. Llibre" wrote:
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("c onnstring"))

Juan T. Llibre
ASP.NET MVP
===========
"Rudy" <Ru**@discussions.microsoft.com> wrote in message news:BD**********************************@microsof t.com...
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("C onnString"))

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


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

"Rudy" wrote:
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("C onnString"))

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


Nov 19 '05 #4

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

Similar topics

1
336
by: Tom | last post by:
I have a question.. I am using remoting but on my client side I chose to use an interface. As a result I was wondering if its still possible to place the configuration details into a xml config...
2
1112
by: Ray5531 | last post by:
what is the equivalent of this in C# ? foreach (XmlNode xmlConfigNode in xmlConfigDoc.ChildNodes) Thansk
2
975
by: Ray5531 | last post by:
what is the equivalent of this in C# ? foreach (XmlNode xmlConfigNode in xmlConfigDoc.ChildNodes) Thansk
5
2109
by: bienwell | last post by:
Hi all, I have a problem with using myCommand.ExecuteScalar(). My question is : If the Web setup is incorrect, does it make command ExecuteScalar() work improperly ?? In my program, I was...
5
5716
by: Keith | last post by:
Hello all, I have a C# Windows Forms app. It is in namespace App.GUI. It builds to Nav.exe. I have entered an application level setting using the designer. Its type is string, name is "FOO"...
3
3282
by: John | last post by:
Hi If I use ConfigurationSettings.AppSettings.Set("KeyName", "KeyValue"), where does the KeyName/KeyValue combination ends up? In a file? In windows registry? Thanks Regards
2
3803
by: Thomas Bauer | last post by:
Hello, I have a config file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="Directory" value="C:\_Database\" /> <add key="CloseApplication" value="0" />...
10
1997
by: Descartes | last post by:
Dear All, Coming from another development environment, it appears that I bang my head in the wall on very basic matters, so I hope you can give me a push in the right direction. The...
0
2040
by: Curtin1060 | last post by:
Hi, I have a simple exe.config issue where I'd like to swap out the config file with NAnt/XMLPOKE. I just can't figure out the correct xpath to get to the "file=" attribute. I want to swap in...
0
7212
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7296
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
7364
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...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.