【问题标题】:Connecting to Data Sources in the Script Task在脚本任务中连接到数据源
【发布时间】:2012-05-25 07:04:59
【问题描述】:

我在使用 SSIS 中的脚本任务中的连接管理器时遇到了一些问题。该程序将完美编译,直到我尝试使用环境中设置的连接。

Private Sub InsertLog(ByRef log() As String)
        Dim conn As SqlClient.SqlConnection
        conn = _
            DirectCast(Dts.Connections("ConfigDB").AcquireConnection(Dts.Transaction),  _
            SqlClient.SqlConnection)
        MsgBox(log(0) & "  " & log(1) & "  " & log(2) & "  " & log(3) & Dts.Connections("ConfigDB").ConnectionString.ToString())
End Sub

如果我注释掉 Dim 和 DirectCast 包将成功执行,我可以成功地在消息框中获取连接字符串。

Data Source=PathToServer;Initial Catalog=DB;Provider=...;Integrated Security=...;Application Name=...;Auto Translate=False;

有其他人发生过这种情况吗?

【问题讨论】:

    标签: sql sql-server-2005 ssis


    【解决方案1】:

    我有一个解决方案。它失败的原因是因为提供者和自动翻译,所以我的解决方案是去掉不需要的东西。

    Dim strConnection As String = Dts.Connections("Automation").ConnectionString.ToString()
            Dim regProvider As New Regex("Provider=([^;]*);")
            Dim regTranslate As New Regex("Auto Translate=([^;]*);")
            strConnection = regProvider.Replace(strConnection, "")
            strConnection = regTranslate.Replace(strConnection, "")
            Dim conn As New SqlClient.SqlConnection(strConnection)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-18
      • 1970-01-01
      相关资源
      最近更新 更多