ConnectionString Initialization

J

josephrthomas

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 request. Please review the
stack trace for more information about the error and where
it originated in the code.

Exception Details: System.InvalidOperationException: The
ConnectionString property has not been initialized.
**quote**

i am tryign to connect to a Access db to retieve info to a
repeater using VB.NET...
i dont how to initailize the connection...
i am doin it like so :
<code>
Dim DS As DataSet
Dim MyConnection As New
System.Data.SqlClient.SqlConnection()
Dim MyCommand As
System.Data.SqlClient.SqlDataAdapter

MyConnection = New
System.Data.SqlClient.SqlConnection
(System.Configuration.ConfigurationSettings.AppSettings
("G:\intouch"))
MyCommand = New
System.Data.SqlClient.SqlDataAdapter("select * from
UserID", MyConnection)

DS = New DataSet()
MyCommand.Fill(DS, "UserID")
</code>
i think the prblem lies in here :
MyConnection = New System.Data.SqlClient.SqlConnection
(System.Configuration.ConfigurationSettings.AppSettings
("G:\intouch"))
.....i think i am doin somethin wrong here...can someone
pls
btw my MSAcess db name is intouch.mdb
help????tks...
..
 
P

Patrice Scribe

What if you display the connection string you read from the config file ?
(the name for this entry is a bit weird)
 
S

sorry me newbie

i dunno how to...i am very very new at this.....pls gimme
some example and links...
tks a lot...really appreciate your help..
 
P

Patrice Scribe

Once you initialized the connection string, add something like :

Response.Write(MyConnection.ConnectionString)


For now I suspect that the connection string is not read as you expect (and
would be "empty").

The configuration file is web.config and AppSettings returns an entry that
is stored inside this file.

The fact that you use a driver letter and a name for this entry let me think
you would expect to read this from somewhere else.

Displaying the connection string would allow to see if it has the value you
expect or if it is empty (probably because AppSettings doesn't work as you
expect).

Good luck


Patrice
 
S

Steve

You need to use the Open method: MyConnection.Open()

eg:
Dim DS As DataSet
Dim MyConnection As New System.Data.SqlClient.SqlConnection()
Dim MyCommand As System.Data.SqlClient.SqlDataAdapter

MyConnection = New
System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationSettin
gs.AppSettings("G:\intouch"))
MyConnection.Open() '-- New code here
MyCommand = New System.Data.SqlClient.SqlDataAdapter("select * from UserID",
MyConnection)
DS = New DataSet()
MyCommand.Fill(DS, "UserID")
MyConnection.Close() '-- New code here

Rock and roll.

SG
 
S

Simon Aspden

The System.Data.SqlClient namespace is only for connecting to Sql Server
databases. For any other database, including MS Access, you should use the
System.Data.OleDb namespace. For the record you may also use OleDb to access
Sql Server databases - I have never had any need to use the SqlClient
namespace.

ie. Your first line would be:
Dim MyConnection As New System.Data.OleDb.OleDbConnection()

You should be able to work out what to put in the Connection String property
with the following steps:
1) using the form designer in Visual Studio, dragging an OleDbConnection
onto the form
2) using the wizard (accessible from the connection string property in the
properties window) to link to your Access DB via the Jet data provider.
3) The connection string will be displayed in the properties window when you
have finished with the Wizard. You should be able to copy and paste this to
your code.

Hopefully this is a good starter and you can work out the rest from there.

All the best.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top