Archive

Posts Tagged ‘SqlConnection’

Get data from web.config

Thursday, 24 April, 2008 2 comments

Any data
——————————————————
store:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="admins" value="esetov_b, lobanov_v"/>
</appSettings>
...

get:
string admins = ConfigurationManager.AppSettings["Admins"];

Connection String
——————————————————
store
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ASPGConnectionString" connectionString="Data Source=DS;Initial Catalog=basename;Persist Security Info=True;User ID=user;Password=psw"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
...

get
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["ASPGConnectionString"].ConnectionString);