Thursday, March 22, 2012

ConnectionString Property

I am having trouble initializing my connection. This is the code:

DimDBConnPhone As NewSqlConnection(ConfigurationManager.AppSettings("DBConnPhone"))

Dim DBConnClient As NewSqlConnection(ConfigurationManager.AppSettings("DBConnClient"))

Dim Sqlcomm1 As New SqlCommand

Dim Sqlcomm2 As New SqlCommand

DBConnPhone.Open()

DBConnClient.Open()

Once I start debugging, it stops and give me the error "The ConnectionString Property was not initialized" Any suggestions?

If you want to retrieve connection strings, you should use ConfigurationManager.ConnectionStrings property, not ConfigurationManager.AppSettings. So the code changes to:

Dim DBConnPhone As New SqlConnection(ConfigurationManager.ConnectionStrings("DBConnPhone"))

Dim DBConnClient As New SqlConnection(ConfigurationManager.ConnectionStrings("DBConnClient"))

...

|||I did that and it said that Value of type 'System.Configuration.ConnectionStringSettings' cannot be converted to 'String'|||Dim DBConnClient As New SqlConnection(ConfigurationManager.ConnectionStrings("DBConnClient").ConnectionString)|||I didn't get any errors with that, but I also did not see where the newrecord was inserted into the table. I got to check my code some more.Thanks

No comments:

Post a Comment