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 : VB Script Performance importing from SQL Server to QuickBooksSearch Forum

Forum Home > QODBC - ODBC Driver for QuickBooks > QODBC SQL Support Forum

 New Topic 
 
 Post Reply 
[1]  
 VB Script Performance importing from SQL Server to QuickBooks 
 Author   Message 
  utiliware 
  
 Group: Members 
 Posts: 2 
 Joined: 2006-04-18 
 Profile
 Posted : 2006-04-18 07:50:01
I am programming an import utility from SQL server 2000 to QB Enterprise. I have ran into numerous problems trying to get the VB script to work. When the script works it takes hours to import 80 to 90 records. Is this normal? Please look at my code below and make recommendations.

Thanks,

-- Bill



Function Main()

Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3

Const adCmdUnknown = &H0008
Const adCmdText = &H0001
Const adCmdTable = &H0002
Const adCmdStoredProc = &H0004

set mySourceConn = CreateObject("ADODB.Connection")
set mySourceRecordset = CreateObject("ADODB.Recordset")
mySourceConn.Open = "Provider=SQLOLEDB.1;Data Source=(local); Initial Catalog=BTP;user id = 'sa';password=''"
mySourceSQLCmdText = "Select * from CustomerName"
mySourceRecordset.Open mySourceSQLCmdText, mySourceConn, adOpenKeyset

If mySourceRecordset.RecordCount < 1 Then
    Main = DTSTaskExecResult_Failure
Else
    dim myDestSQL, myLookupSQL, myCount

    for countr = 1 to mySourceRecordset.RecordCount

        set myQBConn = CreateObject("ADODB.Connection")
        set myQBRecordset = CreateObject("ADODB.Recordset")
        myQBConn.Open =  "Provider=MSDASQL.1;Persist Security Info=False;Data Source=QuickBooks Data;OLE DB Services=-2;"
        myLookupSQLCmdText = "SELECT * FROM CUSTOMER WHERE NAME =  " & "'" & mySourceRecordset.Fields("QBCustomer").value & "'"
        
        myQBRecordset.Open myLookupSQLCmdText, myQBConn, adOpenKeyset
        
        
        If myQBRecordset.RecordCount = 0 Then
            myQBConn.Close
            set myQBConn1 = CreateObject("ADODB.Connection")
            myQBConn1.Open =  "Provider=MSDASQL.1;Persist Security Info=False;Data Source=QuickBooks Data;OLE DB Services=-2;"
            
            myDestSQL = "INSERT INTO " & """" & "customer" & """" & " ("
            myDestSQL = myDestSQL  & """" & "Name" & """" & ", "
            myDestSQL = myDestSQL  & """" & "billAddressAddr1" & """" & ", "
            myDestSQL = myDestSQL  & """" & "billAddressAddr2" & """" & ", "
            myDestSQL = myDestSQL  & """" & "billAddressCity" & """" & ", "
            myDestSQL = myDestSQL  & """" & "billAddressState" & """" & ", "
            myDestSQL = myDestSQL  & """" & "billAddressPostalCode" & """"
            
            myDestSQL = myDestSQL & ") VALUES ("
            myDestSQL = myDestSQL & "'" & mySourceRecordset.Fields("QBCustomer").value & "'" & ", "
            myDestSQL = myDestSQL & "'" & mySourceRecordset.Fields("address1").value & "'" & ", "
            myDestSQL = myDestSQL & "'" & mySourceRecordset.Fields("address2").value & "'" & ", "
            myDestSQL = myDestSQL & "'" & mySourceRecordset.Fields("city").value & "'" & ", "
            myDestSQL = myDestSQL & "'" & mySourceRecordset.Fields("state").value & "'" & ", "
            myDestSQL = myDestSQL & "'" & mySourceRecordset.Fields("zip").value & "'"
            myDestSQL = myDestSQL & ")"
            'msgbox myDestSQL
            myQBConn1.Execute myDestSQL
            myQBConn1.Close

        End If
        
        mySourceRecordset.MoveNext

    Next

    Main = DTSTaskExecResult_Success

End If

End Function 

 
William Dale 
 
  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-04-18 10:07:12

Name doesn't have a jump-in (which acts like a index when using a where clause), so your test to see if a customer exists needs to use FullName not Name! But the main reason for this customer transfer taking hours is because for 90 records you are starting and closing QuickBooks 180 times .... that alone will take hours. Your code should go something like this instead :-

Function Main()

Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3

Const adCmdUnknown = &H0008
Const adCmdText = &H0001
Const adCmdTable = &H0002
Const adCmdStoredProc = &H0004

set mySourceConn = CreateObject("ADODB.Connection")
set mySourceRecordset = CreateObject("ADODB.Recordset")
mySourceConn.Open = "Provider=SQLOLEDB.1;Data Source=(local); Initial Catalog=BTP;user id = 'sa';password=''"
mySourceSQLCmdText = "Select * from CustomerName"
mySourceRecordset.Open mySourceSQLCmdText, mySourceConn, adOpenKeyset

If mySourceRecordset.RecordCount < 1 Then
    Main = DTSTaskExecResult_Failure
Else
    dim myDestSQL, myLookupSQL, myCount

    set myQBConn = CreateObject("ADODB.Connection")
    set myQBRecordset = CreateObject("ADODB.Recordset")
    myQBConn.Open =  "Provider=MSDASQL.1;Persist Security Info=False;Data Source=QuickBooks Data;OLE DB Services=-2;"

    for countr = 1 to mySourceRecordset.RecordCount

        myLookupSQLCmdText = "SELECT FULLNAME FROM CUSTOMER WHERE FULLNAME =  " & "'" & mySourceRecordset.Fields("QBCustomer").value & "'"
       
        myQBRecordset.Open myLookupSQLCmdText, myQBConn, adOpenKeyset
       
       
        If myQBRecordset.RecordCount = 0 Then
           
            myDestSQL = "INSERT INTO " & """" & "customer" & """" & " ("
            myDestSQL = myDestSQL  & """" & "Name" & """" & ", "
            myDestSQL = myDestSQL  & """" & "billAddressAddr1" & """" & ", "
            myDestSQL = myDestSQL  & """" & "billAddressAddr2" & """" & ", "
            myDestSQL = myDestSQL  & """" & "billAddressCity" & """" & ", "
            myDestSQL = myDestSQL  & """" & "billAddressState" & """" & ", "
            myDestSQL = myDestSQL  & """" & "billAddressPostalCode" & """"
           
            myDestSQL = myDestSQL & ") VALUES ("
            myDestSQL = myDestSQL & "'" & mySourceRecordset.Fields("QBCustomer").value & "'" & ", "
            myDestSQL = myDestSQL & "'" & mySourceRecordset.Fields("address1").value & "'" & ", "
            myDestSQL = myDestSQL & "'" & mySourceRecordset.Fields("address2").value & "'" & ", "
            myDestSQL = myDestSQL & "'" & mySourceRecordset.Fields("city").value & "'" & ", "
            myDestSQL = myDestSQL & "'" & mySourceRecordset.Fields("state").value & "'" & ", "
            myDestSQL = myDestSQL & "'" & mySourceRecordset.Fields("zip").value & "'"
            myDestSQL = myDestSQL & ")"
            'msgbox myDestSQL
            myQBConn.Execute myDestSQL         

        End If
       
        mySourceRecordset.MoveNext

    Next

    myQBConn.Close

    Main = DTSTaskExecResult_Success


End If

End Function 

 

  Top 
  utiliware 
  
 Group: Members 
 Posts: 2 
 Joined: 2006-04-18 
 Profile
 Posted : 2006-04-22 12:57:40
The lookups are case sensitve. How do you do a lookup with the "name" not case sensitive? (I need 'bill" to equal 'BILL" for a given lookup.

Thanks in advance.

-- Bill 

 
William Dale 
 
  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-04-22 14:12:24

You do: {fn LCASE("Name")} so bill, Bill and BILL will all be the same.

See: What String Functions can be used with QODBC? for more.

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2007-02-09 21:35:05

See also: Using DTS to Load QuickBooks Data into Microsoft SQL Server for more on how to transfer all the QuickBooks tables.

 

  Top 
 New Topic 
 
 Post Reply 
[1]  

Jump to