Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server: Snapshot transaction problem with synonyms in Express Edition

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

like image 244
Marc Avatar asked Feb 01 '26 00:02

Marc


1 Answers

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.

like image 189
Marc Avatar answered Feb 03 '26 17:02

Marc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!