Click to See Complete Forum and Search --> : Connection String WOES
jesus4u
May 23rd, 2003, 08:21 AM
Something that I need advise on how to make more efficient is this:
When you drag and drop the design time sqlDataAdapter on let's say 10 aspx pages, .NET creates a separate connection string in the code behind for each page. Problem is when I have to move onto a production server I then need to go to each page and manually change the connection string. IT would be nice if .NET would offer a centralized class for the connection strings.
What do you suggest I do?
Thanks
Lethal
May 23rd, 2003, 08:26 AM
Originally posted by jesus4u
IT would be nice if .NET would offer a centralized class for the connection strings.
They do, check out the web.config file. You can store your connection string in there, as well as any other string data.
Cander
May 23rd, 2003, 08:34 AM
in web.config in the configuration element
<appSettings>
<add key="SQLConn" value="Initial Catalog=BRS;Integrated Security=SSPI;Data Source=(local);user id=Cander;password=*****"
<add key="Watchdir" value="c:\watchdir"/>
</appSettings>
You can get the value whenever you need it:
System.Configuration.ConfigurationSettings.AppSettings("SQLConn").ToString()
Lethal
May 23rd, 2003, 10:21 AM
I was to lazy to post a sample. Thanks Cander
jesus4u
May 23rd, 2003, 10:54 AM
cool, thanks
jesus4u
May 23rd, 2003, 11:08 AM
Originally posted by Cander
in web.config in the configuration element
<appSettings>
<add key="SQLConn" value="Initial Catalog=BRS;Integrated Security=SSPI;Data Source=(local);user id=Cander;password=*****"
<add key="Watchdir" value="c:\watchdir"/>
</appSettings>
You can get the value whenever you need it:
System.Configuration.ConfigurationSettings.AppSettings("SQLConn").ToString()
Where exactly do I place it? Under :
<configuration>
<system.web>
Cander
May 23rd, 2003, 11:10 AM
inside the <configuration> one but outside the <system.web> one
jesus4u
May 23rd, 2003, 11:12 AM
I did that and tget this error:
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: This is an unexpected token. Expected 'NAME'. Line 6, position 2.
Source Error:
Line 4: <appSettings>
Line 5: <add key="SQLConn" value="data source=X-2000;initial catalog=Intranet;integrated security=SSPI;persist security info=False;workstation id=X-2000;packet size=4096"
Line 6: </appSettings>
Line 7:
Line 8: <system.web>
Cander
May 23rd, 2003, 11:17 AM
you didnt close the <add element
put /> on the end
jesus4u
May 23rd, 2003, 11:20 AM
duh :rolleyes: :rolleyes: :rolleyes: :rolleyes:
Cander
May 23rd, 2003, 11:21 AM
Dont worry over it. I did the exact same thing the first time I used that stuff and spent 3 hours trying to figure out what theheck was going on.:D
jesus4u
May 23rd, 2003, 11:23 AM
You have always been helpful! Thanks :)
Cander
May 23rd, 2003, 11:27 AM
Your welcome. :D
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.