I am getting this QBFC10 error `System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
The error points to this code sessionManager.BeginSession(@"D:\CompanyFile.qbw", ENOpenMode.omDontCare); below.
If remove the file path @"D:\CompanyFile.qbw" and leave it empty "" it works. But that is not the intention. I need to have the file path there in order for me to run the application even if QuickBooks is not running.
private void BtnQuery_Click(object sender, EventArgs e)
{
bool sessionBegun = false;
bool connectionOpen = false;
QBSessionManager sessionManager = null;
try
{
sessionManager = new QBSessionManager();
IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 10, 0);
requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
IItemInventoryQuery ItemInventoryQueryRq = requestMsgSet.AppendItemInventoryQueryRq();
sessionManager.OpenConnection2("", "AppName", ENConnectionType.ctLocalQBD);
connectionOpen = true;
sessionManager.BeginSession(@"D:\CompanyFile.qbw", ENOpenMode.omDontCare);
sessionBegun = true;
IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
sessionManager.EndSession();
sessionBegun = false;
sessionManager.CloseConnection();
connectionOpen = false;
String xml = responseMsgSet.ToXMLString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
if (sessionBegun)
{
sessionManager.EndSession();
}
if (connectionOpen)
{
sessionManager.CloseConnection();
}
}
}
I also raised this issue with Intuit Developer support awaiting their response. I am hoping anyone here is familiar with QuickBooks API (QBFC).