我想将一个表的某些记录从一个Mysql DB传输到另一个(2个不同的IP地址)。我的两个数据库都通过ODBC连接,并且两个表都作为Access DB中的表链接。
currentdb.execute "insert into Table_DB1 (col1,col2,col3) select col1, col2, col3 from Table_DB1 where col3 between #2020/01/01 0:00:00# and #2020/01/02 23:59:59#"
Table_DB1的col3上有一个索引,并且此选择只有60k条记录。但是它要么很慢,要么Access停止响应。是否有一种更快的方法在Access VB中的2个远程数据库之间传输数据?
我为源表和目标表创建了ADODB连接和记录集,如下所示。传输速度可以接受。
Dim Con_Dest As New ADODB.Connection
Dim Con_Sour As New ADODB.Connection
Dim Rs_Sour As New ADODB.Recordset
Dim Rs_Dest As New ADODB.Recordset
Dim Str_SqlSour As String
Dim Str_SqlDest As String
Dim Str_Sql As String
Con_Sour.Open "dsn=orderreport;uid=ps_exp_user;pwd=ps_expuser123"
Con_Dest.Open "dsn=dataanalysis;uid=david.zeng;pwd=ebdvmFa_qxv2"
Str_SqlSour = "select * from Table_Source"
Rs_Sour.Open Str_SqlSour, Con_Sour
Rs_Dest.Open "Table_Dest", Con_Dest, adOpenDynamic, adLockOptimistic
Rs_Sour.MoveFirst
Do Until Rs_Sour.EOF
With Rs_Dest
.AddNew
.Fields("AAA").Value = Rs_Sour.Fields("Col1")
.Fields("AAB").Value = Rs_Sour.Fields("Col2")
.....
.Update
End With
Rs_Sour.MoveNext
Loop