SQL Server:Express Edition 中的同义词快照事务问题

发布于 2024-07-14 17:52:36 字数 1111 浏览 11 评论 0原文

我们有 2 个数据库,例如 DB1 和 DB2。
DB1 包含还访问 DB2 中数据的所有存储过程。
DB1 使用同义词来访问 DB2 中的表。
(在我们的情况下,使用同义词是一项要求)

在 SQL Server 2005 Developer Edition 的所有情况下,这都可以完美地工作。

然而,在 Express Edition 中,当我们执行以下操作时,我们会遇到异常:
1 重新启动 SQL Server
2 在 DB1 中执行以下代码:

设置事务隔离级别快照
开始交易
声明 @sQuery varchar(max)
set @sQuery = '从 synToSomeTableInDB2 选择 *'
执行 (@sQuery)
提交事务

这将导致以下错误:

数据库“...”中的快照隔离事务失败,因为当前事务启动时数据库未恢复。 数据库恢复后重试事务。

当在没有 EXEC 的情况下使用或在 Developer Edition 上运行时,相同的选择查询可以很好地传递。
步骤 1 中重新启动服务器非常重要,因为一旦连接到 DB2,代码在 SQL Server Express Edition 上也可以正常运行。

有谁知道这是什么? 我们需要能够使用 EXEC 进行一些动态查询。 我们已经查过 MSDN,搜索过 Google,... 任何帮助是极大的赞赏。

---编辑:09年3月10日
正如下面与 Ed Harper 讨论的那样,我已为此提交了一份错误报告。
请参阅 https://connect.microsoft.com/SQLServer/feedback/ViewFeedback .aspx?FeedbackID=422150

We have 2 databases, say DB1 and DB2.
DB1 contains all the stored procedures which access also data in DB2.
DB1 uses synonyms to access the tables in DB2.
(Using synonyms is a requirement in our situation)

This works perfectly fine in all situations with SQL Server 2005 Developer Edition.

However in the Express Edition, we get an exception when we do the following:
1 Restart SQL Server
2 Execute the following code within DB1:

set transaction isolation level snapshot
begin transaction
declare @sQuery varchar(max)
set @sQuery = 'Select * from synToSomeTableInDB2'
exec (@sQuery)
commit transaction

This will result in the following error:

Snapshot isolation transaction failed in database '...' because the database was not recovered when the current transaction was started. Retry the transaction after the database has recovered.

The same select query passes fine when used without the EXEC or when run on the Developer Edition.
Restarting the server in step 1 is important as once a connection was made to DB2, the code runs also fine on SQL Server Express Edition.

Does anyone have an idea what this is? We need to be able to use EXEC for some dynamic queries.
We've already checked MSDN, searched Google, ...
Any help is greatly appreciated.

--- Edit: March 10 09
As discussed with Ed Harper below, I've filed a bug report for this.
See https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=422150

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小…红帽 2024-07-21 17:52:36

通过 Microsoft Connect 发现,问题在于在 SQL Server Express Edition 上,AUTO_CLOSE 选项默认设置为 true
将此选项更改为 false 可以解决该问题。

As found out via Microsoft Connect, the problem is that by default on SQL Server Express Edition the AUTO_CLOSE option is set on true.
Changing this option to false fixes the problem.

情归归情 2024-07-21 17:52:36

该错误消息表明查询失败,因为执行查询时服务重新启动后 SQL Server 仍在恢复数据库。

无论服务重新启动后经过了多长时间,错误是否总是在第一次尝试运行此代码时发生?

能否从SQL Server日志中确认数据库重启后是否正常恢复?

The error message suggests that the query fails because SQL server is still recovering the database following the service restart when you execute your query.

Does the error always occur on the first attempt to run this code, regardless of the time elapsed since the service was restarted?

Can you confirm from the SQL Server log that the database is recovering correctly after the restart?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文