1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Connectionstrings in webconfig STANDARD?

Discussion in 'C#' started by nubsii, May 28, 2008.

  1. #1
    The glorious internet has a vast collection of articles on this topic, some of which were even kind enough to mention that they were written centuries ago.

    (asp.net 2.0)
    Is this 'the way' to store connection strings?
    In this example I have two connection strings, one for my test environment and another for production. Toggling comments will toggle which server I hit.
    SEMrush
    
      <connectionStrings>
        <remove name="SqlServer"/>
        
        <!-- offline; my test environment -->
        <add name="SqlServer" 
             connectionString="Data Source=myComputer\\sqlexpress;Initial Catalog=myproduct-test;Integrated Security=SSPI"
             providerName="System.Data.SqlClient" />
        
        <!-- online; my server aka production -->
        <!--      
        <add name="SqlServer"
               connectionString="Server=myserver.com;Database=mydb;Uid=myuser;Pwd=mypw"
               providerName="System.Data.SqlClient" />
             -->
        
          </connectionStrings>
    
    Code (markup):
    The code to access this stored connection string is:
    
    string connectionString = ConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString;
    
    Code (markup):
    Am I cutting edge or am I a noob??????

    Thanks for readin'
     
    nubsii, May 28, 2008 IP
    SEMrush
  2. nubsii

    nubsii Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'd also like to add that I have copied my connection strings into the above web.config and previously they were strings in some app_code class. My sql connection will no longer open. Does this have to do with SSPI?
     
    nubsii, May 28, 2008 IP
  3. Jhar

    Jhar Peon

    Messages:
    318
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That is generally how you should set up connection strings. Usually you don't use SSPI but instead have Integrated Security=True if you are using SQL express on your development machine.
     
    Jhar, May 28, 2008 IP
    nubsii likes this.