Troubleshooting: Severe delay between connection creation and command execution in VB Code
Problem Description
Below is a simple application running a QODBC stored procedure and dumping the results into a .NET DataSet. The command line app below seems to freeze for approximately 6 minutes before completing successfully (regardless of whether QuickBooks is running or not).
Module Module1 Public Sub Main() Dim strQB, strQBPath As String Dim conQB As New System.Data.Odbc.OdbcConnection If Environment.GetCommandLineArgs.Length = 2 Then strQBPath = "Q:\corporate\test.qbw" '************************************************************** '* QuickBooks Database Connection '************************************************************** conQB.ConnectionString = "Driver={QODBC Driver for QuickBooks};DFQ=" & strQBPath & ";OpenMode=F;OLE DB Services=- 2;OptimizerOn=No;" conQB.Open() strQB = "sp_report CustomTxnDetail show Date, AccountNumber, Account, AccountType, Amount, Class parameters DateFrom = {d'2010-07-01'}, DateTo = {d'2010-07-31'}, SummarizeRowsBy = 'TotalOnly'" Dim da As New System.Data.Odbc.OdbcDataAdapter(strQB, conQB) Dim ds As New DataSet da.Fill(ds, "Transaction") conQB.Close() End If End Sub End Module In the SDK message file, we could see a 6-minute delay between "Connection opened by..." and "Opening the file..."
Solutions
Add an attribute " <MTAThread()> _" before the main code as follows: And please see the link for more: http://support.microsoft.com/kb/828988
Module Module1 <MTAThread()> _ Public Sub Main() Dim strQB, strQBPath As String Dim conQB As New System.Data.Odbc.OdbcConnection
'If Environment.GetCommandLineArgs.Length = 2 Then
'strQBPath = "Q:\corporate\test.qbw" strQBPath = "C:\work\temp\QODBCQA\sample.qbw" '************************************************************** '* QuickBooks Database Connection '************************************************************** conQB.ConnectionString = "Driver={QODBC Driver for QuickBooks};DFQ=" & strQBPath & ";OpenMode=F;OLE DB Services=-2;OptimizerOn=No;"
conQB.Open()
strQB = "sp_report CustomTxnDetail show Date, AccountNumber, Account, AccountType, Amount, Class parameters DateFrom = {d'2010-07-01'}, DateTo = {d'2010-07-31'}, SummarizeRowsBy = 'TotalOnly'"
Dim da As New System.Data.Odbc.OdbcDataAdapter(strQB, conQB) Dim ds As New DataSet da.Fill(ds, "Transaction")
conQB.Close()
End Sub
End Module
|