Friday 7 December 2012

how to write connection string app.config in c#


Application Configuration File.

Open the file and it will be like this (without the key setting, that is my default setting I added to the file) :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings >
    <add name ="DbConnection" connectionString ="Data Source=USER-PC;Initial Catalog=CategoricalClustering;User Id=sa;Password=home;" providerName ="System.Data.SqlClient"/>
  </connectionStrings>
</configuration>

Then in code, we need the assembly we need to manage the configuration file:
1using System.Configuration;

Actually is very easy, to read a configuration just do this:

        string conString = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString;


3 comments:

  1. Nice.It's very shortest way to connection string app.config in c#.

    ReplyDelete
  2. ya it works.But i need more details abt deploying the codes

    ReplyDelete