473,320 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ConnectionString property has not been initialized

I am trying to create an application in my VS 2002 application. I took some
of the code from my web page where it works fine.

I can connect fine from my Sql Query Analyser to both my local Sql Server
and off Sql Server machines.

But I am getting the following error from my "objConn.Open()".

Is this a problem from going from my web to a normal application?

The error is:

The ConnectionString property has not been initialized

My code is:

Imports System.Data
Imports System.Data.SqlClient

....

Dim dbReader As SqlDataReader
Dim ConnectionString As String =
System.Configuration.ConfigurationSettings.AppSett ings("Persist Security
Info=False;Data Source=balair.interez.com;Initial Catalog=InterezData;User
ID=xxx;Password=xxxx;")
Dim objConn As New SqlConnection(ConnectionString)
Dim CommandText As String = "GetCandidateSearchDrops"
Dim objCmd As New SqlCommand(CommandText, objConn)
objCmd.CommandType = CommandType.StoredProcedure
With objCmd.Parameters
.Add("@CompanyID", SqlDbType.Int).Value = 153973
End With
objConn.Open()
dbReader = objCmd.ExecuteReader

Thanks,

Tom
Jan 19 '06 #1
2 5337
> I can connect fine from my Sql Query Analyser to both my local Sql Server
and off Sql Server machines.

But I am getting the following error from my "objConn.Open()". Dim dbReader As SqlDataReader
Dim ConnectionString As String =
System.Configuration.ConfigurationSettings.AppSett ings("Persist Security
Info=False;Data Source=balair.interez.com;Initial Catalog=InterezData;User
ID=xxx;Password=xxxx;")
Dim objConn As New SqlConnection(ConnectionString)

What your code is doing is trying to fetch a key from the .config file whose
name is the content of your connection string.

Here:

In App.Config:

<add key="connectionString" value="your actual connection string here" />
In your VB code:

Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient

Public Class Foo

Public Sub DoStuff()

Dim cnstr As String =
ConfigurationSettings.AppSettings("connectionStrin g")
Dim cn As New SqlConnection(cnstr)
' etc.

End Class

You see, on the first "Dim" line, you are asking for the value of the item
whose key is named "connectionString". The value that is returned is
whatever is in the value attribute in the config file. Then you can go
about your business :)
--
Peace & happy computing,

Mike Labosh, MCSD MCT
"Escriba coda ergo sum." -- vbSensei
Jan 19 '06 #2

"Mike Labosh" <mlabosh_at_hotmail.com> wrote in message
news:eX*************@TK2MSFTNGP11.phx.gbl...
I can connect fine from my Sql Query Analyser to both my local Sql Server and off Sql Server machines.

But I am getting the following error from my "objConn.Open()".
Dim dbReader As SqlDataReader
Dim ConnectionString As String =
System.Configuration.ConfigurationSettings.AppSett ings("Persist Security
Info=False;Data Source=balair.interez.com;Initial Catalog=InterezData;User ID=xxx;Password=xxxx;")
Dim objConn As New SqlConnection(ConnectionString)

What your code is doing is trying to fetch a key from the .config file

whose name is the content of your connection string.

Here:

In App.Config:

<add key="connectionString" value="your actual connection string here" />
In your VB code:

Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient

Public Class Foo

Public Sub DoStuff()

Dim cnstr As String =
ConfigurationSettings.AppSettings("connectionStrin g")
Dim cn As New SqlConnection(cnstr)
' etc.

End Class

You see, on the first "Dim" line, you are asking for the value of the item
whose key is named "connectionString". The value that is returned is
whatever is in the value attribute in the config file. Then you can go
about your business :)

So what I need to do in my application code is just put the connection
string directly into the variable. I tried that and it worked.

Thanks,

Tom
--
Peace & happy computing,

Mike Labosh, MCSD MCT
"Escriba coda ergo sum." -- vbSensei

Jan 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: TPSreport | last post by:
I log on to the cookieless application, work within it for awhile, jump to a URL outside the application, then return to the application. As soon as a db call is required, I get the error below. ...
2
by: Kamal | last post by:
Hi everyone, I've created a user control that calls some method from a class that set the connection string, the connection string is stored in the App.Config file. When i try to add that...
5
by: josephrthomas | last post by:
hi...i am getting a error here...saying : **quote** The ConnectionString property has not been initialized. Description: An unhandled exception occurred during the execution of the current web...
6
by: Tony | last post by:
Dear All, When I run an example program on the http://www.dotnetjunkies.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/data/datagrid1.src&file=VB\datagrid1.aspx&font=3 ...
10
by: Laura K | last post by:
Tried all kinds of things. I get the error. The ConnectionString property has not been initialized. Any help appreciated. ...
5
by: Kent Johnson | last post by:
Hi all, I have accidentally deleted my web.config file so I'll have to recreate it. I have tried this in my Web.config file: <configuration> <appSettings> <add key="ConnectionString"...
4
by: QC | last post by:
Hi, this morning found that my Service had crashed, and the error was "Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized". I have no...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.