Home »
.NET 4.0 »
OleDbConnection string with ConfigurationManager
OleDbConnection string with ConfigurationManager
Web config
<add
name="MyConnectionString"
connectionString="Data Source=SRV-MY-SQL\SQLCLSTR12;
Initial Catalog=MyDatabaseName;
Persist Security Info=True;User ID=MyUser;Password=MyPassword"
providerName="System.Data.SqlClient" />
Code behind or markup page
'defines sql connection
Dim connString As String
connString = ConfigurationManager.ConnectionStrings("MyConnectionString").ToString
Dim ConnDB As New OleDbConnection("Provider=sqloledb;" & connString)
'define oledbcommand
Dim cmd As New OleDbCommand("SELECT * _
"FROM my_table _
"WHERE name='Mike' ;", ConnDB)
Dim reader As OleDbDataReader
Tags: ASP.NET, OleDbConnection, SQL, Visual Studio