InteropServices.COMException on Access.DoCMD.RunSQL error

2

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!!! :(

c#
sql
ms-access
interop
comexception
asked on Stack Overflow Jul 17, 2012 by user1532518 • edited Jul 18, 2012 by user1532518

1 Answer

3

It's probably far too late to help the OP, but hopefully this will help someone else like me who couldn't find an answer.

For me, the solution to the The RunSQL action was canceled. error was to open the MDB in Access and click the Enable Content button. This file was generated on a client's machine (external to our network, of course). Judging by the fact TortoiseSVN showed the file as changed after that and I was able to commit those changes, it seems that enabling content physically modifies the file. It must store some permissions inside the file, perhaps even storing permissions on a per machine basis, and use them even when executing via Interop.

This was with MS Access 2010.

answered on Stack Overflow Jun 5, 2013 by jpmc26

User contributions licensed under CC BY-SA 3.0