Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL Server-两个数据库上的非分布式事务_Sql_Sql Server_Transactions - Fatal编程技术网

SQL Server-两个数据库上的非分布式事务

SQL Server-两个数据库上的非分布式事务,sql,sql-server,transactions,Sql,Sql Server,Transactions,我正在尝试将我遇到的问题本地化 与2个数据库及其事务行为相关。 我在一个SQL Server 2008 R2实例上创建了两个数据库。 测试1 测试2 test1有一个表table_1 test2有一个表table_2 两个表都有一个ID(int)列和一个值(string)列。 两者都只有一行ID=1。 然后在SQL Server Management Studio中, 在某些窗口1中,我可以 use test1 begin transaction update test1.dbo.Tabl


我正在尝试将我遇到的问题本地化
与2个数据库及其事务行为相关。

我在一个SQL Server 2008 R2实例上创建了两个数据库。

测试1
测试2

test1有一个表table_1
test2有一个表table_2

两个表都有一个ID(int)列和一个值(string)列。
两者都只有一行ID=1。

然后在SQL Server Management Studio中,
在某些窗口1中,我可以

use test1

begin transaction

update test1.dbo.Table_1
set
value = 'TEST-100'
where
ID = 1 


update test2.dbo.Table_2
set
value = 'TEST-200'
where
ID = 1 

commit transaction  --- but I don’t run the commit yet --- 
然后在另一个窗口2中,我会执行

select * From test1.dbo.Table_1
with (nolock) 

select * From test2.dbo.Table_2
with (nolock) 
select * From test1.dbo.Table_1
这样我可以看到两个尚未提交的值。

但是如果在窗口2中,我会这样做

select * From test1.dbo.Table_1
with (nolock) 

select * From test2.dbo.Table_2
with (nolock) 
select * From test1.dbo.Table_1

select * From test2.dbo.Table_2
这些选择的语句将挂起。

所以我的问题是:这是来自
窗口1,跨越两个数据库?似乎是因为

select * From test2.dbo.Table_2
也挂起,这对我来说意味着test2.dbo.Table_2
已登记在我启动的同一事务中
在窗口1中。

但为什么此事务的行为类似于分布式事务?
这正常吗?原因是什么?那是什么 SQL Server中未记录的功能?有没有

可以解释我看到的行为的引用?

当一个查询跨越两个数据库时,您的事务将升级为由MSDTC处理的分布式事务。这是一种正常的方式,在没有显式使用BEGIN DISTRIBUTED TRANSACTION语句的情况下发生。

感谢您的回复。你能给我指出一些参考资料吗?使用这个链接作为切入点:它不是由MSDTC处理的(我知道,因为我的MSDTC是禁用的,它可以工作)。它在SQL Server内部处理。我也不认为它具有分布式事务的属性。@usr:“当在本地事务中执行分布式查询时,事务将自动升级为分布式事务”,链接:technet.microsoft.com/en-us/library/ms188386.aspx。你对这个答案投了反对票吗?是的,我投了反对票,我证明这个答案是错误的(禁用MSDTC并尝试一下)。在tran中使用多个DBs仅在多个连接或跨服务器完成时使用分布式事务。您引用的文档对于真正的分布式事务是有效的,但此处不使用它们。