1

我在使用 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;

这事发生在别人身上过吗?

4

1 回答 1

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)
于 2012-05-17T18:05:43.520 回答