Cannot connect to a database

  • Thread starter Thread starter HS1
  • Start date Start date
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
 
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.
 
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.
 
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) .
 
Back
Top