Мы используем SMO для передачи таблиц с одного сервера на другой в SQL Server 2016.
В течение некоторого времени передача успешно выполняется только один из трех раз только на 1 сервере, и мы всегда получаем одно и то же сообщение об ошибке, которое не говорит о многом: при передаче данных произошла ошибка. Смотрите внутреннее исключение для деталей.
Этот же пакет был развернут в наших 4 средах (Dev, Test, Qa и Prod) и работает каждый день. Однако эту проблему мы получаем только в тесте.
Наши администраторы баз данных не делают много, чтобы помочь нам найти причину, по которой это добавляется. Можете ли вы дать мне подсказку, где посмотреть? Этот пакет служб SSIS долгое время не обновлялся, а встроенная версия одинакова во всех средах.
Вот наш скрипт .vb в пакете:
Public Sub Main()
'
' Source and Destination Servers
'
' MsgBox(Dts.Variables("User::SourceServer").Value.ToString)
Dim srvSourceName As String = Dts.Variables("SourceServer").Value.ToString '"brdsqldev"
Dim srvDestinationName As String = Dts.Variables("DestinationServer").Value.ToString '"brdsqldev"
Dim bt(0) As Byte
'
' Source and Destination Databases
'
Dim dbSourceName As String = Dts.Variables("SourceDB").Value.ToString
Dim dbDestinationName As String = Dts.Variables("DestinationDB").Value.ToString
Try
Dts.Log("The Transfer starts", 0, bt)
Dts.Log("Transfer starts with tables", 0, bt)
Dts.Log("Transfer starts with tables" & srvSourceName, 0, bt)
Dts.Log("Transfer starts with tables" & srvDestinationName, 0, bt)
Dts.Log("Transfer starts with tables" & dbSourceName, 0, bt)
Dts.Log("Transfer starts with tables" & dbDestinationName, 0, bt)
' TableExists()
Transfer(srvSourceName, srvDestinationName, dbSourceName, dbDestinationName, CType(Dts.Variables.Item("myDataTable").Value, System.Data.DataTable), TransferObjectType.Table)
' Transfer(srvSourceName, srvDestinationName, dbSourceName, dbDestinationName, CType(Dts.Variables.Item("myDataViews").Value, System.Data.DataTable), TransferObjectType.View)
Dts.Log("Transfer done with tables", 0, bt)
Dts.Log("The Transfer ran successfully", 0, bt)
Dts.TaskResult = ScriptResults.Success
'MessageBox.Show("The transfer ran successfully.")
Catch ex As Exception
Dts.Events.FireError(99, "", ex.Message.ToString(), "", -1)
OutPutError(ex)
Dts.TaskResult = ScriptResults.Failure
'MessageBox.Show("The transfer was aborted.")
End Try
End Sub
Private Sub Transfer(ByVal srvSourceName As String, ByVal srvDestinationName As String, ByVal dbSourceName As String, ByVal dbDestinationName As String, ByVal dataTableToTransfer As DataTable, ByVal type As TransferObjectType)
Try
Dim srcsrv As Server
srcsrv = New Server(srvSourceName)
Dim dbSource As Database
dbSource = srcsrv.Databases(dbSourceName)
Dim dessrv As Server
dessrv = New Server(srvDestinationName)
Dim dbDestination As Database
dbDestination = dessrv.Databases(dbDestinationName)
Dim oleDA As New OleDbDataAdapter
Dim dt As New DataTable
Dim row As DataRow
Dim sMsg As String
Dim xfr As Transfer
Dim bt(0) As Byte
Dts.Log("Transfer Subroutine starts ...", 0, bt)
xfr = New Transfer(dbSource)
xfr.CopyAllTables = False
xfr.Options.WithDependencies = False
xfr.Options.ContinueScriptingOnError = False
xfr.CopyAllRoles = False
xfr.CopyAllLogins = False
xfr.CopyAllDatabaseTriggers = False
xfr.CopyAllDefaults = False
xfr.CopyAllPartitionFunctions = False
xfr.CopyAllObjects = False
xfr.CopyAllPartitionFunctions = False
xfr.CopyAllPartitionSchemes = False
xfr.CopyAllRules = False
xfr.CopyAllSchemas = False
xfr.CopyAllSqlAssemblies = False
xfr.CopyAllStoredProcedures = False
xfr.CopyAllSynonyms = False
xfr.CopyAllUserDefinedAggregates = False
xfr.CopyAllUserDefinedDataTypes = False
xfr.CopyAllUserDefinedFunctions = False
xfr.CopyAllUserDefinedTypes = False
xfr.CopyAllUsers = False
xfr.CopyAllViews = False
xfr.CopyAllXmlSchemaCollections = False
xfr.CopySchema = True
xfr.DestinationDatabase = dbDestination.Name
xfr.DestinationServer = dessrv.Name
xfr.DestinationLoginSecure = True
xfr.DropDestinationObjectsFirst = False
Select Case type
Case TransferObjectType.Table
xfr.CopyData = True
Case TransferObjectType.View
xfr.CopyData = False
Case Else
Dts.Log("Unknown object transfer type. (-99)", -99, bt)
Dts.TaskResult = ScriptResults.Failure
'Throw New Exception("Unknown object transfer type.")
End Select
dt = dataTableToTransfer
Dts.Log("Transfer Subroutine just before Row Count...", 0, bt)
If dt.Rows.Count > 0 Then
Dts.Log("Transfer Row Count > 0...", 0, bt)
For Each row In dt.Rows
Dim tblSourceName As String
Dim tblSourceSchema As String
tblSourceSchema = row("transferschema").ToString()
tblSourceName = row("transferobject").ToString
Select Case type
Case TransferObjectType.Table
xfr.ObjectList.Add(dbSource.Tables(tblSourceName.ToString, tblSourceSchema.ToString))
Case TransferObjectType.View
xfr.ObjectList.Add(dbSource.Views(tblSourceName.ToString, tblSourceSchema.ToString))
Case Else
Dts.Events.FireError(99, "Transfer Object", "Unknows object type", "", -1)
Dts.TaskResult = ScriptResults.Failure
'Throw New Exception("Unknown object transfer type.")
End Select
Next
Dts.Events.FireInformation(1, "", "Just before transfering data", "", -1, False)
xfr.TransferData()
End If
Catch ex As InternalSmoErrorException
Dim bt(0) As Byte
Dts.Events.FireError(99, "Transfer Objects", ex.Message.ToString(), "", -1)
OutPutError(ex)
Dts.TaskResult = ScriptResults.Failure
End Try
End Sub
Private Sub OutPutError(ex As Exception)
Dim ErrorLogDir As String
Dim OutPutFileName As String
ErrorLogDir = System.IO.Path.GetDirectoryName(Dts.Connections("ExportNightlyTransfer.xml").ConnectionString.ToString())
OutPutFileName = ErrorLogDir + "\\" + Dts.Variables("PackageName").Value.ToString() + "ErrorReport" + Now.ToString("yyyyMMddHHmmss") + ".txt"
Using sw As StreamWriter = New StreamWriter(OutPutFileName)
sw.WriteLine(Now.ToString())
sw.WriteLine("Package Name: " + Dts.Variables("PackageName").Value.ToString())
sw.WriteLine("Task Name: " + Dts.Variables("TaskName").Value.ToString())
sw.WriteLine(ex.Message.ToString())
sw.WriteLine(ex.GetBaseException.ToString())
sw.WriteLine(ex.StackTrace.ToString())
End Using
End Sub
Заранее спасибо за помощь.
Mylene