I make an Pivotcache in C# and later want to connect an Access-database to this pivotcache, but i get an error on the 'Add'.
The 'old' code in VB looks like this (and did work):
With WbkXL_Workbook.PivotCaches.Add(SourceType:=Excel.XlPivotTableSourceType.xlExternal).Connection = strConnection
.CommandType = Excel.XlCmdType.xlCmdSql
.CommandText = strCommand
.CreatePivotTable(TableDestination:=WstXL_Worksheet_Bst.Range("A3"), _
TableName:="Draaitabel1")
End With
The c# that i have created is as follows:
Excel.
PivotCache PCache;PCache = WbkXL_Workbook.PivotCaches().Add(Excel.
XlPivotTableSourceType.xlExternal, System.Type.Missing);PCache.Connection = strConnection;
PCache.CommandType = Excel.
XlCmdType.xlCmdSql;PCache.CommandText = strCommand;
PCache.CreatePivotTable(WstXL_Worksheet_Bst.get_Range(
"A3", System.Type.Missing), "Draaitabel1", System.Type.Missing, System.Type.Missing);The Error i get is:
AutoUpdateSaveChanges = '((Excel.WorkbookClass)(WbkXL_Workbook)).AutoUpdateSaveChanges' threw an exception of type 'System.Runtime.InteropServices.COMException'
Can anyone please give me a hint

Error on a 'Add' in a Pivotcache in Excel
Andrew Raymond
try
{
// TODO: Add your code here.
}
catch( Exception caught )
{
MessageBox.Show( this, "Exception details:\r\n" + caught.ToString() );
}
Ashwin Jayamohan
Ramakrishna Neela
The MessageBox must be shown when the exception is thrown in the try-statement.
Because i don't know the full stack-trace and message it is hard to fix it, but as far as i can see the problem is in your connection. But you should try to get the exception details first, so you will learn to use this powerfull method and it will provide you all the information to fix the problem.
office of technology
It does not rase an exception.
Only when i set a breakpoint and look into the values of WbkXL_Workbook, I see an exeption error as metioned before "AutoUpdateSaveChanges = '((Excel.WorkbookClass)(WbkXL_Workbook)).AutoUpdateSaveChanges' threw an exception of type 'System.Runtime.InteropServices.COMException'".
When i comment out the code
PCache.Connection = strConnection;
To
PCache.Connection =
"";My code moves on, only offcourse i get no result.
The value of strConnection is as follows and the path is ok because it is the same code as in VB where it did work:
string strConnection;
strConnection = "ODBC;DSN=MS Access-database;DBQ=" + ModPublicDef.StrDbPath + @"\"
+
ModPublicDef.StrDbName + ";DefaultDir=" + System.IO.Directory.GetCurrentDirectory() + @"\"+
"database;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;PWD=rafael;UID=admin;";Does this give you a better idea of the problem
i2adnan
Hello Mr. van de Sande,
How do i make a full stacktrace
Freakie.