Thursday, December 20, 2012

How to add Connection string in Config file (.Net)

Leave a Comment
Step 1:
    Right Click on project->Add->New Item->General
    Select “Application Configuration File” and click on “Add”

Step 2:
    Add bellow section in config file and change DatabaseName,Database,Username,Password according to connect server
</configuration>
    <appSettings>
        <add key="ConnectionString" value="Data Source=Persist Security Info=True;Initial Catalog=DatabaseName;Data Source=DatabasePath;User ID=UserName;Password=Password" /> 
    </appSettings>
</configuration>

Step 3:
    Add reference of System.Configuration.

Step 4:
    Add bellow code where you want to use connection string  
Configuration.ConfigurationManager.AppSettings("ConnectionString").ToString()

0 comments: