以下代码块位于SSIS包中的脚本任务(执行转储)中。递归调用该脚本以获取数据库中的表列表:
Function ImportSQLServerToAccess(ByVal sMDBFile As String, ByVal sSource As String, ByVal sDestination As String, ByVal sServer As String, ByVal sDatabase As String) As Boolean
Dim AccessConn As System.Data.OleDb.OleDbConnection
If System.Environment.OSVersion.Version.Major >= 6 Then
AccessConn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + sMDBFile + "")
Else
AccessConn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sMDBFile + "")
End If
AccessConn.Open()
Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT * INTO " + sDestination + " FROM [" + sSource + "] IN '' [ODBC;Driver={SQL Server};Server=" + sServer + ";Database=" + sDatabase + ";Trusted_Connection=yes];", AccessConn)
AccessCommand.ExecuteNonQuery()
AccessCommand.Dispose()
AccessConn.Close()
End Function
第一次调用执行转储脚本任务时,查询执行正常并将数据转储到mdb中,但在此之后每隔一段时间就会失败,但“ODBC - 连接到'{SQL Server} DEV01'失败” 。我不确定为什么连接第二次失败但第一次成功。是否有任何建议的解决方法?