f



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
0
4/1/2004 8:08:51 PM
comp.databases.ms-access 42670 articles. 0 followers. Post Follow

1 Replies
2307 Views

Similar Articles

[PageSpeed] 17

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-----

0
me2968 (1474)
4/2/2004 2:38:06 AM
Reply: