我正在使用以下结构将数据从 Excel 上传到 SQL Server:
Private Sub ado_upload()
Dim objConnection As New ADODB.Connection
Dim objCommand As New ADODB.Command
Dim strSQL As String
Dim strDSN As String
Dim intCounter As Integer
strDSN = "provider=SQLOLEDB;" _
& "server=<server>;" _
& "database=<database>;" _
& "uid=<uid>;pwd=<pwd>;" _
& "trusted_connection=false;"
With objConnection
.ConnectionString = strDSN
.Open
End With
strSQL = "SET NOCOUNT ON; " _
& "INSERT INTO dbo.[table1] ( [col1] ) VALUES ( ? );"
With objCommand
.ActiveConnection = objConnection
.CommandText = strSQL
.Prepared = True
.Parameters.Append .CreateParameter("col1", adInteger, adParamInput)
For intCounter = 0 To 9
.Parameters("Col1").Value = intCounter
.Execute
Next intCounter
End With
End Sub
该过程的速度取决于服务器和运行该过程的计算机之间的地理距离。在服务器本身上它很快(在 10 分钟内插入 300,000 次),在该国的另一端它相对较慢(300,000 次插入可能需要几个小时)。远程上传通过 VPN 进行。
我认为网络延迟一定会减慢进程。有没有办法绕过网络延迟,或调整 VPN 以加快上传速度?
谢谢!