Cannot connect to a database

H

HS1

Hello

Me again

I want to create a connection using SqlDataConnection with a a Access
database as following:
Dim da1 As New System.Data.SqlClient.SqlDataAdapter()

Dim da2 As New System.Data.SqlClient.SqlDataAdapter()

Dim conn As System.Data.SqlClient.SqlConnection

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Password="";User
ID="";Data Source=C:\myDatabase.mdb"

da1 = New System.Data.SqlClient.SqlDataAdapter("Select * From Clients",
conn)

da2 = New System.Data.SqlClient.SqlDataAdapter("Select * From Jobs", conn)

However it did not work. There is an error at "conn.ConnectionString"
claimed that "Object reference not set to an instance of an object."

Note: I typed correct database name and location. myDatabase has no password
or Id

Could you please help

Many thanks
S.Hoa
 
I

Imran Koradia

AFAIK, the Sql* classes are /only/ for Sql Server. So, your SqlConnection
can be used to connect to a Sql Server only. To connect to an access
database, you'll need to use either an OleDbConnection or an OdbcConnection.

hope that helps..
Imran.
 
C

Christopher Kurtis Koeber

Off topic but what does AFAIK mean?

Christopher
Imran Koradia said:
AFAIK, the Sql* classes are /only/ for Sql Server. So, your SqlConnection
can be used to connect to a Sql Server only. To connect to an access
database, you'll need to use either an OleDbConnection or an
OdbcConnection.

hope that helps..
Imran.
 
W

W.G. Ryan eMVP

You have two major problems here. As imran pointed out, you can't use
SqlClient w/ access and you'll need to instaniate your connection before you
try referencing it. Any time you get that exception, make sure you
instantiated the object (with new) .
 

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

Top