Results 1 to 13 of 13

Thread: Connection String WOES

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Thumbs down Connection String WOES

    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

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496

    Re: Connection String WOES

    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.

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    in web.config in the configuration element

    Code:
    	<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()
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I was to lazy to post a sample. Thanks Cander

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    cool, thanks

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    Originally posted by Cander
    in web.config in the configuration element

    Code:
    	<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 :

    Code:
    <configuration>
     
      <system.web>

  7. #7
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    inside the <configuration> one but outside the <system.web> one
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    I did that and tget this error:

    Code:
    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>

  9. #9
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you didnt close the <add element

    put /> on the end
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    duh

  11. #11
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    You have always been helpful! Thanks

  13. #13
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Your welcome.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width