lundi, décembre 26, 2005

Reading a connexion string from the app.config

I was trying for a while to read my connection string from the app.config file, but finaly it's ery simple :

Here is a example of connection string declaration

connectionString="Data Source=MyServer;Initial Catalog=Mydb;Integrated Security=True"
providerName="System.Data.SqlClient" />

let's try to put the server name into a textBox (txtServerName )
using System.Configuration;
using System.Data.SqlClient;

SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();
csb.ConnectionString = Properties.Settings.Default.dbConnectionString.ToString();

txtServerName.text = csb.DataSource.ToString();

Aucun commentaire: