Transaction context in use by another session

孤者浪人 提交于 2019-12-01 02:55:34

Loopback linked servers can't be used in a distributed transaction if MARS is enabled.

Loopback linked servers cannot be used in a distributed transaction. Trying a distributed query against a loopback linked server from within a distributed transaction causes an error, such as error 3910: "[Microsoft][ODBC SQL Server Driver][SQL Server]Transaction context in use by another session." This restriction does not apply when an INSERT...EXECUTE statement, issued by a connection that does not have multiple active result sets (MARS) enabled, executes against a loopback linked server. Note that the restriction still applies when MARS is enabled on a connection.

http://msdn.microsoft.com/en-us/library/ms188716(SQL.105).aspx

I solve It. I was using the same linked server to call the second procedure and then into the procedure I was using the same linked server.

It's very Easy, only we have to know the restricctions of linked servers.

I have resolved it by removing linked server used in the stored procedure and then called stored procedure by the same linked server. It wasnt working in DEV environement.

I also got the same error in our DEV environemnt, moving the linked databases to another sql instance resolved the issue. In our production environment these databases are already on separate instances

In my case I was using SQL 2005 and got "transaction context in use by another session" when running Insert....exec over a linked server. The fix for me was to patch from SP2 build 3161 to SP3. SP2 cumulative 5 is supposed to fix though.

https://support.microsoft.com/en-us/kb/947486

When remote database sits on the same server,configure the linked server without specifying the database server ip / hostname and port. Just the database name should be sufficient.

I was getting the same "transaction context in use by another session error" when trying to run an UPDATE query:

 BEGIN      TRAN
--ROLLBACK  TRAN
--COMMIT    TRAN
UPDATE  did 
SET     did.IsProcessed = 0,
        did.ProcessingLockID = NULL
FROM    [proddb\production].DLP.dbo.tbl_DLPID did (NOLOCK)
WHERE   did.dlpid IN ('bunch of GUIDs')
--WHERE   did.DLPID IN (SELECT DLPID FROM @TableWithData)

However I didn't realize I was already trying to run this on the DLP database on the ProdDb\Production server. Once I removed that "[proddb\production].DLP.dbo." prefix from the query, it worked fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!