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

access MS-Access database in C# Windows Application

P: n/a
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
Share this Question
Share on Google+
1 Reply


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