使用ADO.NET进行SSIS脚本转换错误

时间:2011-08-31 14:31:34

标签: ado.net ssis

我在执行SSIS包时遇到错误,指出Incorrect syntax near ')'.。 DFT中的脚本转换组件抛出错误。据我所知,它被sqlReader = sqlCmd.ExecuteReader()线抛出。我已经看了几天了,似乎无法弄清楚导致错误的原因。我已经在下面包含了脚本组件的内容。有人有什么想法吗?

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports System.Data.SqlClient

Public Class ScriptMain
Inherits UserComponent

Dim connMgr As IDTSConnectionManager90
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
Dim sqlParam As SqlParameter

Public Overrides Sub AcquireConnections(ByVal Transaction As Object)

    connMgr = Me.Connections.connTalisma
    sqlConn = CType(connMgr.AcquireConnection(Nothing), SqlConnection)

End Sub

Public Overrides Sub PreExecute()

    sqlCmd = New SqlCommand("SELECT Name FROM dbo.Category WHERE CatID = @catid)", sqlConn)
    sqlParam = New SqlParameter("@catid", SqlDbType.Int)
    sqlCmd.Parameters.Add(sqlParam)

End Sub

Public Overrides Sub ReleaseConnections()

    connMgr.ReleaseConnection(sqlConn)

End Sub

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
    Dim sqlReader As SqlDataReader
    Dim delimitedField As String = Row.FinalCallReason
    Dim delimiter As String = ";"
    Dim tempField As String

    If Not (String.IsNullOrEmpty(delimitedField)) Then
        Dim DelimitedListArray() As String = delimitedField.Split(New String() {delimiter}, StringSplitOptions.RemoveEmptyEntries)
        For Each item As String In DelimitedListArray
            sqlCmd.Parameters("@catid").Value = CInt(item)
            MsgBox(item)
            Try
                sqlReader = sqlCmd.ExecuteReader()
                tempField = tempField + ";" + sqlReader.GetString(0)
            Catch e As Exception
                MsgBox("Error: " + e.Message)
            End Try
        Next
    End If
    Row.FinalCallReason = tempField
End Sub

End Class

1 个答案:

答案 0 :(得分:1)

在代码的以下部分中,在SqlCommand对象初始化语句中将 @catid)更改为 @catid

删除括号。这不是必需的。括号导致查询失败,因此错误消息Incorrect syntax near ')'

Public Overrides Sub PreExecute()

    sqlCmd = New SqlCommand("SELECT Name FROM dbo.Category WHERE CatID = @catid)", sqlConn)
    sqlParam = New SqlParameter("@catid", SqlDbType.Int)
    sqlCmd.Parameters.Add(sqlParam)

End Sub