473,606 Members | 2,409 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;Ne twork Library=dbmssoc n;Initial
Catalog=mycatal og;User ID=****;Passwor d=*****;"

This is the line of code that I would like to use
Dim myconnection As New
SqlConnection(C onfigurationSet tings.AppSettin gs("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(S QL_CONNECTION_S TRING)
I get "Not declared" error.
I also tried it this way,
''' Protected Const SQL_CONNECTION_ STRING As String = "MyConnecti on"

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 1490
Ty this in web.config:

<configuratio n>
<appSettings>
<add key="connstring " value="server=D ata Source=192.168. 100.120,xxxx;Ne twork Library=dbmssoc n;Initial Catalog=mycatal og;User ID=****;Passwor d=*****;"/>
</appSettings>
</configuration>

Then, in your aspx file, call it like this :
Dim myConnection as New SqlConnection(C onfigurationSet tings.AppSettin gs("connstring" ))

Juan T. Llibre
ASP.NET MVP
===========
"Rudy" <Ru**@discussio ns.microsoft.co m> wrote in message news:BD******** *************** ***********@mic rosoft.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;Ne twork Library=dbmssoc n;Initial
Catalog=mycatal og;User ID=****;Passwor d=*****;"

This is the line of code that I would like to use
Dim myconnection As New
SqlConnection(C onfigurationSet tings.AppSettin gs("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(S QL_CONNECTION_S TRING)
I get "Not declared" error.
I also tried it this way,
''' Protected Const SQL_CONNECTION_ STRING As String = "MyConnecti on"

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(C onfigurationSet tings.AppSettin gs("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;Ne twork Library=dbmssoc n;Initial
Catalog=mycatal og;User ID=xxxx;Passwor d=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:

<configuratio n>
<appSettings>
<add key="connstring " value="server=D ata Source=192.168. 100.120,xxxx;Ne twork Library=dbmssoc n;Initial Catalog=mycatal og;User ID=****;Passwor d=*****;"/>
</appSettings>
</configuration>

Then, in your aspx file, call it like this :
Dim myConnection as New SqlConnection(C onfigurationSet tings.AppSettin gs("connstring" ))

Juan T. Llibre
ASP.NET MVP
===========
"Rudy" <Ru**@discussio ns.microsoft.co m> wrote in message news:BD******** *************** ***********@mic rosoft.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;Ne twork Library=dbmssoc n;Initial
Catalog=mycatal og;User ID=****;Passwor d=*****;"

This is the line of code that I would like to use
Dim myconnection As New
SqlConnection(C onfigurationSet tings.AppSettin gs("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(S QL_CONNECTION_S TRING)
I get "Not declared" error.
I also tried it this way,
''' Protected Const SQL_CONNECTION_ STRING As String = "MyConnecti on"

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 =
ConfigurationSe ttings.AppSetti ngs("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;Ne twork Library=dbmssoc n;Initial
Catalog=mycatal og;User ID=****;Passwor d=*****;"

This is the line of code that I would like to use
Dim myconnection As New
SqlConnection(C onfigurationSet tings.AppSettin gs("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(S QL_CONNECTION_S TRING)
I get "Not declared" error.
I also tried it this way,
''' Protected Const SQL_CONNECTION_ STRING As String = "MyConnecti on"

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 file ? I have not seen any examples of this does anyone know how I can do this ? All I've seen are example such as below where an interface calling the server as such. but I would like to not use this and instead call the config file as its easily...
2
1124
by: Ray5531 | last post by:
what is the equivalent of this in C# ? foreach (XmlNode xmlConfigNode in xmlConfigDoc.ChildNodes) Thansk
2
980
by: Ray5531 | last post by:
what is the equivalent of this in C# ? foreach (XmlNode xmlConfigNode in xmlConfigDoc.ChildNodes) Thansk
5
2112
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 using ExecuteScalar() to count the number of records from the query. The return value is always 0. If number record is 0 then it will go the Page1.aspx page by (response.redirect) . If not, it will go to Page2.aspx page. The result is it's...
5
5726
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" and value is "monkey". I've tried the following ways to retrieve the value and only one works: //Returns null Configuration config = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location); string monkey =...
3
3289
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
3817
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" /> <add key="Extension" value="*.txt,*.log" />
10
2012
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 application that I work on will consist of - a mainform with a usual menu and toolbar and not much more. - a number of modal data editing forms with various edit controls, an OK button and a Cancel button
0
2046
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 "US, UK, ..." depending on the target regions. Thanks, Craig
0
8016
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7955
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8440
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8431
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8306
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6773
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5966
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5466
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.