By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,693 Members | 1,233 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,693 IT Pros & Developers. It's quick & easy.

Cannot connect to a database

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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.

"HS1" <so*@slingshot.co.nz> wrote in message
news:1096855654.312670@ftpsrv1...
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

Nov 21 '05 #2

P: n/a
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) .

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"HS1" <so*@slingshot.co.nz> wrote in message
news:1096855654.312670@ftpsrv1...
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

Nov 21 '05 #3

P: n/a
Off topic but what does AFAIK mean?

Christopher
"Imran Koradia" <no****@microsoft.com> wrote in message
news:Of**************@TK2MSFTNGP15.phx.gbl...
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.

"HS1" <so*@slingshot.co.nz> wrote in message
news:1096855654.312670@ftpsrv1...
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


Nov 21 '05 #4

P: n/a
AFAIK - As Far As I Know
I've been there :)

Imran.

"Christopher Kurtis Koeber" <c_******@myrealbox.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Off topic but what does AFAIK mean?

Christopher
"Imran Koradia" <no****@microsoft.com> wrote in message
news:Of**************@TK2MSFTNGP15.phx.gbl...
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.

"HS1" <so*@slingshot.co.nz> wrote in message
news:1096855654.312670@ftpsrv1...
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



Nov 21 '05 #5

P: n/a
Imran,
AFAIK - As Far As I Know
I've been there :)


I am almost sure that is in this question "IK" is enough for you.

:-)

Cor
Nov 21 '05 #6

P: n/a
lol ! good one Cor..

"Cor Ligthert" <no************@planet.nl> wrote in message
news:ez**************@TK2MSFTNGP14.phx.gbl...
Imran,
AFAIK - As Far As I Know
I've been there :)


I am almost sure that is in this question "IK" is enough for you.

:-)

Cor

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.