好的,这有点复杂,所以我会尽量简化它。我有一个带有反向触发器的SQL Server视图。 Trigger调用CLR UDF(C#),称之为MyUDF。 MyUDF尝试使用文字连接字符串打开第二个连接,即
using (SqlConnection connection2 = new SqlConnection(newConnString)) { ...
我已确认连接字符串是好的。我还确认UDF在更新触发器之外工作正常。但是,当更新触发器调用时,我得到如下所示的DotNet错误。我甚至尝试根据这个KB启用DTC而没有运气:http://msdn.microsoft.com/en-us/library/dd327979.aspx
由于权限,我需要打开第二个连接。当前连接可能没有足够的权限来执行必要的查询,因此我无法使用"context connection=true"
问题:在这种情况下有没有办法打开第二个连接?
这是DotNet错误(SQL Server 2008标准,Windows 2008 x86,DotNet 4):
A .NET Framework error occurred during execution of user-defined routine or aggregate "MyUDF":
System.Data.SqlClient.SqlException: Transaction context in use by another session.
System.Data.SqlClient.SqlException:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
at System.Data.SqlClient.SqlInternalConnectionTds.PropagateTransactionCookie(Byte[] cookie)
at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)
at System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction)
at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at UserDefinedFunctions.MyUDF(SqlString data)