I've been searching around to no avail for a supposedly simple connection to an (MS)Access database (.mdb).
I use Office 2007, Visual Studio 2010, it is a C# Winform application, on a x64 (64 bit) OS, with the app running in x86 (32 bit) mode.
I'm already able to easily access a SQL-server database but on (MS)Access I'm completely stuck. I’m trying to connect to a database that is placed in my Dropbox.
My connection code:
//(string SQL = "select * from Quickmem";)
public static DataTable SelectALL(string SQL)
{
var appDataPath = Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData);
var dbPath = System.IO.Path.Combine(appDataPath, "Dropbox\\host.db");
var lines = System.IO.File.ReadAllLines(dbPath);
var dbBase64Text = Convert.FromBase64String(lines[1]);
string folderPath = System.Text.ASCIIEncoding.ASCII.GetString(dbBase64Text);
// Actual path (which he correctly finds): C:\Users\<username>\Dropbox
folderPath += "\\Agenda.mdb";
string strAccessConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + folderPath;
string strAccessSelect = SQL;
DataSet myDataSet = new DataSet();
OleDbConnection myAccessConn = null;
myAccessConn = new OleDbConnection(strAccessConn);
OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect, myAccessConn);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);
myAccessConn.Open();
myDataAdapter.Fill(myDataSet, "QuickMem");
myAccessConn.Close();
DataTableCollection dta = myDataSet.Tables;
DataTable DT = dta[0];
return DT;
}
The current exception I’m getting is
“System.Data.OleDb.OleDbException occurred Message=Data type mismatch in criteria expression. Source=Microsoft Office Access Database Engine ErrorCode=-2147217913 StackTrace: at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) InnerException: .”
In my experimenting, I’ve come across many issues all breaking on the same line:
myDataAdapter.Fill(myDataSet, "QuickMem");
Quickmem being a table in my database.
Any help or input will be appreciated.