469,625 Members | 1,091 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

access MS-Access database in C# Windows Application

Hi, I am trying to access the MS Access database on my local machine
in C# Windows Application in Visual Studio.NET.

But it seems that it does not work. I use the Microsoft Application
Blocks to access the database.

I have tried 2 possible connection strings.

-----------------------------------------

str_1 = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" + DBFilePath;

str_2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBFilePath;

//SqlHelper is the class in the Microsoft Application Blocks
SqlHelper.ExecuteNonQuery( str_1, CommandType.Text, SQL_str);
-----------------------------------

The error message I got is:

"Unknown connection option in connection string: driver." for str_1

and
" Unknown connection option in connection string: provider." for str_2

So I am wondering, where is the problem?
Is it because my connection string for MS Access is specified wrongly?
Or is it because I cannot use SqlHelper to access the MS Access
database? ( I have used SqlHelper class to access the MS SQL server,
and it works)

Your help will be greatly appreciated.
James
Nov 12 '05 #1
1 5110
James wrote:
Hi, I am trying to access the MS Access database on my local machine
in C# Windows Application in Visual Studio.NET.

But it seems that it does not work. I use the Microsoft Application
Blocks to access the database.

I have tried 2 possible connection strings.

-----------------------------------------

str_1 = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" + DBFilePath;

str_2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBFilePath;

//SqlHelper is the class in the Microsoft Application Blocks
SqlHelper.ExecuteNonQuery( str_1, CommandType.Text, SQL_str);
-----------------------------------

The error message I got is:

"Unknown connection option in connection string: driver." for str_1

and
" Unknown connection option in connection string: provider." for str_2

So I am wondering, where is the problem?
Is it because my connection string for MS Access is specified wrongly?
Or is it because I cannot use SqlHelper to access the MS Access
database? ( I have used SqlHelper class to access the MS SQL server,
and it works)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm still learning about C# and ADO.NET, so ...

Usually, anything that begins with SQL, like "SqlHelper," is associated
w/ MS SQL Server. Therefore, it won't work w/ MS Access (JET) db
engine. My guess is you need to use the ODBC or the OLEDB name space to
set up a connection (try the System.Data.OleDb.OleDbConnection classes
first).

OleDbConnection cn = new OleDbConnection();
cn.Provider = "Microsoft.Jet.OLEDB.4.0";

For better info you may want to try the
microsoft.public.dotnet.languages.csharp newsgroup.

- --
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQGzSHIechKqOuFEgEQKLoACcDookU90Qh/0KMXMiU2SqZDOCpbEAoPxK
1ds1qR6FLv0vGKbEqeauLsTu
=Izh4
-----END PGP SIGNATURE-----

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Rob R. Ainscough | last post: by
19 posts views Thread by Rob R. Ainscough | last post: by
6 posts views Thread by Anony Mous | last post: by
2 posts views Thread by =?Utf-8?B?QW50aG9ueSBSb2RyaWd1ZXosIERCQQ==?= | last post: by
1 post views Thread by Dr T | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.