Hi Minty, Field names don't change... I am pushing 147k lines (25 field per line) from a local access table to a sql server table, with VBA. 1st I delete all rows in the server table, then "insert into" the new lines. I do this once per week. Doing an append query in access is much slower. Any other method you suggest that is automated to get data from a local access table to a sql server table?
I changed the code last night and got it down from 750s to 176s... Just guessing about the memory reallocation every time I concatenate a new string to the running string, I created an array of 2000 block of 64k length strings... I limit each item in the array to <65000 characters in length. Now I have approx 1700 string arrays and each string is less then a length of 64000 characters.
Now it takes 6 seconds to create this array full of transaction strings and 170 seconds to write to the server in 4 separate pushes
Code:
start_timer = Timer
loop_thru_lines = UBound(alldata, 2) - LBound(alldata, 2) + 1 ' this is looping thru rows
loop_thru_fields = UBound(alldata, 1) - LBound(alldata, 1) + 1 'This is loooping thru columns, same as rs_local.Fields.Count
Dim blocks_of_64k(1 To 2000) As String
Dim block_used As Integer
block_used = 1
For j = 1 To loop_thru_lines ' this is looping thru rows
For i = 1 To loop_thru_fields 'This is loooping thru columns, same as rs_local.Fields.Count
value_array_1d(i) = alldata(i - 1, j - 1)
Next i
sql_string_returned = Insert_Into_Create_Sql_String_For("[" & sql_server_table_name & "]", field_names_array_1d, value_array_1d)
If Len(blocks_of_64k(block_used)) > 64000 Then
block_used = block_used + 1
Else
block_used = block_used
End If
blocks_of_64k(block_used) = blocks_of_64k(block_used) & sql_string_returned
Next j
sql_string = ""
For i = 1 To 2000
sql_string = sql_string & blocks_of_64k(i)
If i = 500 Or i = 1000 Or i = 1500 or i = 2000 Then
Check_Set_Sql_Server_Connection
SQL_SERVER_ADODB_CN.Execute sql_string
sql_string = ""
End If
Next i