Knowledgebase
[QODBC-Desktop] Severe delay between connection creation and command execution in VB Code
Posted by Juliet (QODBC Support) on 20 October 2010 08:48 AM

Troubleshooting: Severe delay between connection creation and command execution in VB Code

Problem Description

Below is a simple application that runs a QODBC stored procedure and dumps the results to a .NET DataSet. The command line app below seems to freeze for approximately 6 minutes before completing successfully (regardless of QuickBooks 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 that there's 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

(450 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please complete the captcha below (we use this to prevent automated submissions).