The following block of code is within a script task (perform dump) in a SSIS package. The script is recursively called for a list of tables in the database:
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
The first time the perform dump script task is called, the query executes fine and dumps the data into mdb, but fails every other time after that with the exception 'ODBC--connection to '{SQL Server}DEV01' failed'. I am not sure why the connection fails the second time but succeeds the first time. Is there any suggested workaround for this?