Go to Comments





Storing connection string in web.config Asp.Net


Created: 17/06/2013 01:21:45 p.m.




Storing connection string in web.config Asp.Net

In both cases use System.Configuration;
You can get your connection string by using UDL file like here: Basic database connection string


1) Connection string in .NET 2.0 (web.config)
<appSettings>
<add key="ConnString" value="Integrated Security=SSPI;Persist Security Info=False;
Initial Catalog=tests;Data Source=MAK-PC\MSSQLSERVER2008
" /> </appSettings>
Use (C#):
string connString = ConfigurationSettings.AppSettings("ConnString");



2) Connection string in .NET 3.5 (web.config)

<connectionStrings>
<add name="ConnString" connectionString="Integrated Security=SSPI;Persist Security Info=False;
Initial Catalog=tests;Data Source=MAK-PC\MSSQLSERVER2008
" /> </connectionStrings>
Use (C#):
string
connString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;


Microsoft Visual Studio



Comments: