CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Jul 2012
    Location
    .NET4.0 / VS 2010
    Posts
    8

    Trouble using App.Config ConnectionString (String works don't understand code)

    I'm using VS2010 on XP.

    Below is the app.config file i'm trying to use. I don't understand the part about the connection string. I have two calls to the database that uses this same connection string, but i don't know how to use it.

    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
    <connectionStrings>
                   <add name="ConnectionString"  providerName="System.Data.SqlClient"
    	    connectionString="Data Source = cwsqldb; Initial Catalog =
                     Annuals; Integrated Security = True" />
    </connectionStrings>
    
    
    	<appSettings>
    		<add key="fromAddress" value="[email protected]"/>
                              <add key ="ToAddress" value ="[email protected]"/>
    		<add key="ToBcc" value="[email protected]"/>
    		<add key="subject" value="codeworth Connection Audit Alert"/>
    		<add key ="smtp" value="mail88-gwy"/>
    	</appSettings>
    
    </configuration>
    I know I can access the <add key=""> values with the following code.

    Code:
    string fromAddress = ConfigurationManager.AppSettings["fromAddress"].ToString();
    string ToAddress = ConfigurationManager.AppSettings["ToAddress"].ToString();
    But how do i access the connection string? I don't understand that block of code AT ALL! I understand that the connection string is composed of different parts. But i've always seen it as basically one long string separated by semicolons.

    Thanks for your help!
    Last edited by maurices5000; July 19th, 2012 at 11:02 AM.

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

Featured