How to create an Access database using C # and constantly save data in real time

I am currently launching an application that runs around the clock and constantly collects information from OPC-sever.

Now I need to send this information to the database (.accdb file). This should happen very quickly. I get a new value from the server every milliseconds, and I need to send this value to the database at the same speed. Finally, I compress the database into a .zip file at 00:00 every day.

I searched the Internet like a maniac, but I can’t find a β€œmodern” textbook. Everyone I have found so far uses "Microsoft.Jet.OLEDB.4.0" as a provider, but it does not work on my Windows 7 PC.

I made a small application for testing the connections, and I will attach my current code below to give you a hint that I have tried so far, but all this does not seem to work.

private void button1_Click(object sender, EventArgs e)
{
    System.Reflection.Assembly oAssembly = System.Reflection.Assembly.GetExecutingAssembly();
    System.IO.Stream oStream = oAssembly.GetManifestResourceStream("RSLogixDB.accdb");
    System.IO.FileStream fileStream = new System.IO.FileStream("C:\\Users\\sezettersth\\Documents\\RSLogixDB.accdb", System.IO.FileMode.Create);

    byte[] abyt = new byte[oStream.Length];
    oStream.Read(abyt, 0, (int)oStream.Length);
    fileStream.Write(abyt, 0, (int)oStream.Length);
    fileStream.Close();
    if (fileStream != null)
    {
        fileStream.Close();
        fileStream = null;
    }
    if (oStream != null)
    {
        oStream = null;
    }
}

This is the first approach I tried, here I use the home class, which is used to create and write to files. This does not work for .accdb files, unfortunately. (The comments on the first lines refer to the providers I tried.

private void button1_Click(object sender, EventArgs e)
{
    //sFileDia.ShowDialog();
    //Provider=Microsoft.ACE.OLEDB.12.0
    //Povider=.NET Framework Data Provider for OLE DB
    //Povider=Microsoft.Jet.OLEDB.4.0
    //Driver={Microsoft Access Driver (*.mdb, *.accdb)};
    //Data Source=C:\\Users\\sezettersth\\Documents\\RSLogixDB.accdb;
    //Persist Security Info=False;
    //Provider=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\sezettersth\\Documents\\RSLogixDB.accdb;Persist Security Info=False
    string RSLogixDB = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\sezettersth\\Documents\\RSLogixDB.accdb;Persist Security Info=False";
    string RSLogixDBPath = "C:\\Users\\sezettersth\\Documents\\RSLogixDB.accdb";
    OleDbConnection connection = new OleDbConnection(RSLogixDB);
    string connectionStr = connection.ConnectionString;

    //OleDbDataReader dataReader = new OleDbDataReader(RSLogixDB);
    ImportExport textwriter = new ImportExport();
    textwriter.setExportPath(RSLogixDBPath);
    textwriter.endExport();
}

There should be a simple solution, I cannot be the only one using Access without the Microsoft.Jet.OLEDB.4.0 provider.

(I did not run the code for the zip file, and if you have an idea on how to do this, I am glad to hear it, but the focus here is on the database problem.)

: , , Microsoft.ACE.OLEDB.12.0 .accdb, txt , MS Access. .accdb?

+5
4

, , .
, , RSLogixDB.accdb.
, - , , .

SO-:

.

Jet vs ACE

-, ACCDB Jet ACE. Access 2007/2010 , .

, Access 2007/2010 ( Access Runtime), ACE Microsoft.

32/64

, , 32- Office Access. Microsoft 64 , , Excel .

  • Office 32 64
  • 32- 64- ACE- .
  • 2007 2010 ACE, .
  • , .Net- , Access/ACE ( x86, , AnyCPU!).

Access, :

  • , , , ( )

  • , , :

    // Share Mode=16 - use if multiple users must have simultaneous access to the db
    string constr = @"Provider=Microsoft.ACE.OLEDB.12.0;Mode=16;Data Source=C:\...\RSLogixDB.accdb;user id=;password=;";
    
    // Share Mode=12 - exclusive mode if only your app needs access to the db
    string constr = @"Provider=Microsoft.ACE.OLEDB.12.0;Mode=12;Data Source=C:\...\RSLogixDB.accdb;user id=;password=;";
    
  • , (, zip ). : Access , // .accdl.
    , /. , , :
    OLE DB?

, :

  • Access, RSLogixDB.accdb , .
    dummy . , .

  • , , .

  • db, .

  • , . .

  • , ( ), , .accdl , .
    , .
    , , .

  • ADO.Net , DAO. : ( ) .NET/#

+9
+2

, , Jet OLEDB Windows 7, . - Microsoft Access, MDAC Microsoft (MDAC = Microsoft Data Access Components).

You can check if - and if so - which version of MDAC you have by following the instructions at the following link:

http://support.microsoft.com/kb/301202/en-us

+1
source

All Articles