如何将TransactionScope与ODBCConnection一起使用

时间:2019-05-21 09:34:54

标签: vb.net

如何在ODBC连接中使用TransactionScope。

实际上,我客户的数据库服务器位于远程位置,我只能使用ODBC连接字符串与该数据库连接。 我尝试这样做,但问题是当它尝试打开连接时抛出错误"ERROR [25S12] [Microsoft][ODBC SQL Server Driver]Distributed transaction error".

StackTrace:

“位于System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle,RetCode retcode)    在System.Data.Odbc.OdbcConnection.Open_EnlistTransaction(交易事务)    在System.Data.Odbc.OdbcConnectionOpen.EnlistTransaction(交易事务)    在System.Data.Odbc.OdbcConnection.EnlistTransaction(交易事务)    在System.Data.Odbc.OdbcConnection.Open()    在IOS.DataLibrary.DataAccessorODBC.GetDataTable(字符串connstring,字符串sql,Int32 commandTimeOut)在D:\ Projects \ CIOS \ IOS2 \ IOS.DataLibrary \ DataAccessorODBC.vb:行46“

Public Shared Function ExecuteNonQuery(ByVal connstring As String, ByVal sql As String)
    WriteString_Query("Timestamp: " & Now.ToString & vbCrLf & "ConnectionString: " & connstring & vbCrLf & "SQL Fired: " & vbCrLf & sql & vbCrLf & "------------------------------" & vbCrLf)
    Try
        Using cnQODBC As New System.Data.Odbc.OdbcConnection(connstring)
            cnQODBC.ConnectionTimeout = 5
            cnQODBC.Open()
            Using daQODBC As New System.Data.Odbc.OdbcCommand(sql, cnQODBC)
                Return daQODBC.ExecuteNonQuery()
            End Using
        End Using
    Catch ex As Exception
    End Try
    Return Nothing
End Function

谢谢。

0 个答案:

没有答案