Home » .NET 4.0 » SqlConnection from web config file in code behind

SqlConnection from web config file in code behind

test.aspx.vb

Imports System.Data.SqlClient
-------------------------------------
Dim connString As String
connString = ConfigurationManager.ConnectionStrings("MyConnectionString1").ToString
Dim conn As New SqlConnection(connString)

web.config

<connectionstrings>
<add name="MyConnectionString1" 
connectionString="Data Source=MY-SQL-SRV;Initial Catalog=Northwind;
Persist Security Info=True;
User ID=my_user;Password=my_pwd" providerName="System.Data.SqlClient" />
 </connectionstrings>