access MS-Access database in C# Windows Application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James

    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={Micros oft Access Driver (*.mdb)}; DBQ=" + DBFilePath;

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

    //SqlHelper is the class in the Microsoft Application Blocks
    SqlHelper.Execu teNonQuery( str_1, CommandType.Tex t, 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
  • MGFoster

    #2
    Re: access MS-Access database in C# Windows Application

    James wrote:
    [color=blue]
    > 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={Micros oft Access Driver (*.mdb)}; DBQ=" + DBFilePath;
    >
    > str_2 = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" + DBFilePath;
    >
    > //SqlHelper is the class in the Microsoft Application Blocks
    > SqlHelper.Execu teNonQuery( str_1, CommandType.Tex t, 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)[/color]

    -----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.Ole Db.OleDbConnect ion classes
    first).

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

    For better info you may want to try the
    microsoft.publi c.dotnet.langua ges.csharp newsgroup.

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

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

    iQA/AwUBQGzSHIechKq OuFEgEQKLoACcDo okU90Qh/0KMXMiU2SqZDOCp bEAoPxK
    1ds1qR6FLv0vGKb EqeauLsTu
    =Izh4
    -----END PGP SIGNATURE-----

    Comment

    Working...