【问题标题】:SSIS 2016 SMO Transfer error: An error occured while transferring data. See inner exception for detailsSSIS 2016 SMO 传输错误:传输数据时发生错误。有关详细信息,请参阅内部异常
【发布时间】:2018-11-07 16:17:37
【问题描述】:

我们正在使用 SMO 在 SQL Server 2016 上将表从一台服务器传输到另一台服务器。

一段时间以来,仅在 1 台服务器上传输成功的次数仅为 3 次,而且我们总是收到相同的错误消息,这并没有说明太多:传输数据时发生错误。有关详细信息,请参阅内部异常。

同一个包已部署到我们的 4 个环境(Dev、Test、Qa 和 Prod)并且每天都在运行。但是,我们只在测试中遇到了这个问题。

我们的 DBA 没有做太多工作来帮助我们找到附加的原因。你能告诉我在哪里看吗?那个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

提前感谢您的帮助。 亚甲基

【问题讨论】:

  • 错误的详细信息是什么?
  • 我没有任何详细信息。就是这样!我从哪里获得详细信息?
  • 调试窗口中什么都没有?或者您可以单击“复制错误详细信息”按钮的弹出窗口之一(抱歉不确定确切的文本)?
  • 该程序包计划在夜间运行。这是一项真正的双向工作,最多需要 5 个小时才能运行。就像我说的那样,有时它有效,有时它不...历史日志中没有特定的错误信息。有没有办法我们可以以某种方式追踪它?
  • 您可以让失败的步骤记录错误。以下是logging to a file 的说明,但您也可以登录到表格或其他一些选项。

标签: ssis transfer smo ssis-2016


【解决方案1】:

通过添加 Catch innerException 代码,我能够获得有关错误的具体信息。

  Catch ex As Exception
  Dts.Events.FireError(99, "", ex.Message.ToString(), "", -1)
  OutPutError(ex)

  If ex.InnerException IsNot Nothing Then
    Dts.Events.FireError(99, "", ex.InnerException.Message.ToString(), "", -1)
    OutPutError(ex.InnerException.Message.ToString())
  End If


  Dts.TaskResult = ScriptResults.Failure
  'MessageBox.Show("The transfer was aborted.")
End Try

问题解决了!!谢谢你:-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-08
    • 2017-06-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多