I wrote a little program in Visual Studio 2010 to open an Access database, enter a value into a table, and open a form. Pretty simple, and the program works great on my laptop.
The problem arises when I try and run the exe on a second PC. I cannot enter a value into a table. Both computers can open the project with Visual Studio 2010 just fine. The error I receive when I run it is:
"System.Runtime.InteropServices.COMException (0x800A09C5): The RunSQL action was canceled.\r\n at Microsoft.Office.Interop.Access.DoCmd.RunSQL(Object SQLStatement, Object UseTransaction)\r\n at OpenGasAlarmSheet.Program.Main(String[] args) in \Program.cs:line 47"
I pass some arguments into a string to get the equivalent of:
String sql = "INSERT INTO tbl_LOG ([ALARM], [DATE])
VALUES ('KNITERV4', #07-17-2012 10:22:29 AM#);"
And here's the code for part of the program to run that SQL string:
Access.Application oAccess = null;
oAccess = new Access.Application();
oAccess.OpenCurrentDatabase(<file path to mdb>, false);
oAccess.DoCmd.RunSQL(sql); //This is line 47
I've been trying to fix this error for about a week, and I'm completely stuck. Any help would be much appreciated!!!
Thanks, Chris
Edit: 07/18/2012
Here's where I'm at....
Option 1:
String sql = "INSERT INTO tbl_LOG ([ALARM], [DATE])
VALUES ('KNITERV4', #07-17-2012 10:22:29 AM#);";
oAccess.CurrentDb().Execute(sql); //ERROR HERE
Results in.....
PC #1: Works correctly!
PC #2 & #3: Error (see below)
"System.Runtime.InteropServices.COMException (0x8002801D): Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))\r\n at Microsoft.Office.Interop.Access.ApplicationClass.CurrentDb()\r\n at Test.Program.Main(String[] args) in \Program.cs:line 47"
Option 2:
String sql = "INSERT INTO tbl_LOG ([ALARM], [DATE])
VALUES ('KNITERV4', #07-17-2012 10:22:29 AM#);";
oAccess.DoCmd.RunSQL(sql); //ERROR HERE
Results in.....
PC #1: Works correctly!
PC #2 & #3: Error (see below)
"System.Runtime.InteropServices.COMException (0x800A09C5): The RunSQL action was canceled.\r\n at Microsoft.Office.Interop.Access.DoCmd.RunSQL(Object SQLStatement, Object UseTransaction)\r\n at OpenGasAlarmSheet.Program.Main(String[] args) in \Program.cs:line 47"
Option 3:
cn.ConnectionString = oAccess.CurrentProject.Connection.ConnectionString; //ERROR HERE
cn.Open();
rs.ActiveConnection = cn;
rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic;
rs.CursorType = ADODB.CursorTypeEnum.adOpenKeyset;
rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
rs.Open("tbl_LOG");
rs.AddNew("ALARM", "KNITERV4");
rs.UpdateBatch();
Results in.....
PC #1 & #3: Error (see below)
"System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))\r\n at Microsoft.Office.Interop.Access._CurrentProject.get_Connection()\r\n
at Test.Program.Main(String[] args) in \Test\Program.cs:line 38"
PC #2: Works Correctly!!!
I can't get this thing to work on multiple PCs. FRUSTRATING!!! :(