Навигация

Итоги года

Другие ссылки


Реклама

Счётчики


Reading connection string from app.config

03.09.2008 Среда 14:40

Software: .Net, C#

This is how to read connection string from a configuration file (web.config, app.config). Assume you have the following in your configuration file:

<configuration>
<connectionStrings>
<add name="MyConnectionString"
connectionString="Data Source=localhost;Initial Catalog=master;Persist Security Info=True" />
</connectionStrings>
<configuration>
In order to read this string within C# code do this:

1. Add reference to System.Configuration.dll

2.Use this code:

string connString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;