Member Login

Username
Password
Forget Password
New Sign Up
Search Forum

Buy Support
Incidents

If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:

Click Here
If you can't login and post questions or you are having trouble viewing forum posts:
Click Here
Callback
Support

If you live in USA, UK, Canada, Australia or New Zealand, you can leave us details on your question and request us to call you back and discuss them with you personally  (charges apply).

Click Here
 
Buy Support
Incidents
If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:
Click Here

Forum : getrows method adoSearch Forum

Forum Home > QODBC - ODBC Driver for QuickBooks > QODBC v8 Forum

 New Topic 
 
 Post Reply 
[1]  
 getrows method ado 
 Author   Message 
  icabodcam 
  
 Group: Members 
 Posts: 12 
 Joined: 2008-01-31 
 Profile
 Posted : 2008-04-16 08:18:22

Using QODBC with the getrows method can be painfully slow with large query results.  Does anyone have an alternative that is quicker.  I'm trying to script this by geting a row count for the query, define an array with that count of lines to hold the recordset , fill the array to recordset.eof, then close the recordset and connection.  This is in essecence what getrows does, but if I understand how qodbc is processing the xml it'll prevent multiple calls after the initial query. 

In addition to being frustrated with the process, I'm hitting a wall with this, as I'm currently unable to get the records count sent to a variable.   using the query below (in VB.NET, thus the double quotes)  I'm getting an error, this works in the vbdemo (with single quotes of course).  I know this is several issues in one, but I figgure someone else has hit this wall too. 

SELECT COUNT(ListID) as ""COUNT"" FROM Customer UNOPTIMIZED WHERE IsActive=1 and CustomFieldJob LIKE '____-___-__'

 

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2008-04-16 10:11:18

Your .NET Windows Console application needs to use a STA (single-threaded-apartment) threading model. Multi-threading actually slows QODBC down as we need to re-establish a connection to QuickBooks every time the Thread ID changes.

See the msdn .NET Framework Developer Center:  http://msdn2.microsoft.com/en-us/library/system.stathreadattribute.aspx 

Note: ADODB works, but when you loop through the resultant recordset via Recordset.MoveNext(), an additional query is made through QODBC for each record.  These additional queries caused an additional 50 minutes of runtime for a 7000 invoice query.

The first function below demonstrates the ADODB method that took ~1 hour.  The second does the same thing with ODBC and takes less than a minute. 

[STAThread]
static void test1() {
    ADODB.Connection con = new ADODB.Connection();
    con.Open("DSN=SOQB;OLE DB Services=-2", "", "", -1);
    string invoiceSQL =
                "SELECT CustomerRefFullName, RefNumber, TxnDate, BalanceRemaining, AppliedAmount, Memo " +
                "FROM Invoice " +
                "WHERE TxnDate>{d'2006-04-02'}";
        ADODB.Recordset invoiceResult = new ADODB.Recordset();
        invoiceResult.Open(invoiceSQL, con, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, 0);
        while(!invoiceResult.EOF) {
                Console.WriteLine("Invoice #" + invoiceResult.Fields["RefNumber"].Value.ToString());
                invoiceResult.MoveNext();
        }
        con.Close();
}


[STAThread]
static void test2() {
        OdbcConnection con = new OdbcConnection("DSN=SOQB");
        con.Open();
        OdbcDataAdapter dAdapter = new OdbcDataAdapter(
                "SELECT CustomerRefFullName, RefNumber, TxnDate, BalanceRemaining, AppliedAmount, Memo " +
                "FROM Invoice " +
                "WHERE TxnDate>{d'2006-04-02'}", con);
        DataTable result = new DataTable();
        dAdapter.Fill(result);
        DataTableReader reader = new DataTableReader(result);
        while(reader.Read()){
                Console.WriteLine("Invoice #: " + reader.GetString(1));
        }
        con.Close();
}

  

  Top 
  icabodcam 
  
 Group: Members 
 Posts: 12 
 Joined: 2008-01-31 
 Profile
 Posted : 2008-04-16 11:57:41

OK Forgive my rookie questions here, I'm new to using the odbc provider.  I am using QODBC with a remote connector, and am now getting the error: Attempted to read or write protected memory .  I'm feeling ok with my code, so I suspect theres a permission issue here that I'm missing, but I have no idea.  Here is the code I put together after reading your reply.  Can you please shed light on this?

Dim ConnStr As String = "DSN=QuickBooks Data"

Dim CommandStr As String = "SELECT COUNT(ListID) as ""COUNT"" FROM Customer UNOPTIMIZED WHERE IsActive=1 and CustomFieldJob LIKE '____-___-__'"

Dim conn As New System.Data.Odbc.OdbcConnection(ConnStr)

Dim reader As System.Data.Odbc.OdbcDataReader

conn.Open()

Dim Cmd As New System.Data.Odbc.OdbcCommand(CommandStr, conn)

reader = Cmd.ExecuteReader()

Label1.Text = reader(1)

reader.Close()

conn.Close()

As I've said I'm sure I've got errors here, please be gentle. Thanks.

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2008-04-16 12:33:57

A "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.” type error often means a error in coding. Try this:

cnQODBC = New System.Data.Odbc.OdbcConnection("DSN=QuickBooks Data")
cnQODBC.Open()
daQODBC = New System.Data.Odbc.OdbcDataAdapter("SELECT ListID, FullName, CompanyName FROM Customer", cnQODBC)
dsQODBC = New System.Data.DataSet
daQODBC.Fill(dsQODBC)
DataGrid1.DataSource = dsQODBC
DataGrid1.DataBind()

 

  Top 
  icabodcam 
  
 Group: Members 
 Posts: 12 
 Joined: 2008-01-31 
 Profile
 Posted : 2008-04-17 01:04:32

Big difference there, down to 4 mins for 262 records from 10 mins.  I must admit at this point that I am unclear about your initial comment about STA.  Right now I've only changed from ado to odbc, but I think you must be on to something that I am missing, and I've not gotten the complete understanding yet.  How does the thread state relate in this matter, and how am I to go about changing my wayward path? 

 

 

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2008-04-17 10:59:30

See the msdn .NET Framework Developer Center:  http://msdn2.microsoft.com/en-us/library/system.stathreadattribute.aspx 

 

  Top 
 New Topic 
 
 Post Reply 
[1]  

Jump to