[thelist] VB.NET 2.0 Connection String

Casey Crookston caseyc at IntelliSoftmn.com
Tue Jun 26 14:01:59 CDT 2007


This should really be simple, but I am having a hard time with it.  In a vb.net 2.0 / VS 2005 app, I want to store my connection string in the app.config, as such:
 
<connectionStrings>
<add name="StorkConnection" connectionString="Data Source=xxx; Initial Catalog=xxx; Persist Security Info=True; User ID=xxx; Password=xxx; Asynchronous processing = true " providerName="System.Data.SqlClient" />
</connectionStrings>
 
But I am having trouble referencing this string in the code behind.  I have looked over Google, but I just can't seem to nail it.  It's gettting frustrating.  I've searched for:
 
vb.net 2005 connection string in app.config
 
vb.net connection string app.config
 
connection string app.config visual studio 2005
 
And other variations.  I did find this, which seems to work initially but errors out at run-time when I try to open the connection:
 
Private cn As New SqlClient.SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("ConnectionString"))
 
Can someone point me in the right direction, please!!
 
Casey




More information about the thelist mailing list