I am currently in the process of making an application that runs 24/7 and constantly collects information from an OPC-sever.
What I need to do now is to send this information to a database (.accdb-file). This need to happen very, very quickly. I fetch a new value from the server every millisecond and I need to send that value to the database at the same speed. Lastly I'm compressing the database to a .zip-file at 00:00 every day.
I have been searching the web like a maniac but I can't seem to find an "Up-to-date" tutorial. Every one I have found so far uses "Microsoft.Jet.OLEDB.4.0" as provider but it doesn't exsist on my Windows 7 PC.
I have made a small application to test connections with and I'll attach my current code bellow to give you a hint of what I have tried so far, none of this seems to work, though.
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 a homemade class that is used for creating and writing to files. It didn't work for .accdb-files, unfotunately. (The comments on the first lines include providers that I have 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 has to be a simple solution to this, I can't be the only one using Access without the "Microsoft.Jet.OLEDB.4.0" provider.
(I haven't started the code for zipping the file and if you have an idea on how to do that I'm happy to hear it, but the main focus here is the database issue.)
UPDATE: The problem might not lie on the provider as I initially though, Microsoft.ACE.OLEDB.12.0 allows me to create a .accdb-file but it is just an empty txt-file with a fancy extension basically and it cannot be opened or used with MS Access. How do I make a working .accdb-file?
accdb
. And if your C# application is AnyCPU and you're on a 64-bit platform then you need to use the 64-bit version (Access 2010 x64 Database Engine) – Algorism