Friday, 4 November 2011

Time Out During Upgrade - Toggle READ_COMMITTED_SNAPSHOT Failed

Utilities 3e can sometimes fail when running the Upgrade process and throws a time out error. The Upgrade process then hangs and doesn't respond to the stop command/button. The only way out is to close the whole Utilities app.

The error message has a comment of "Toggle READ_COMMITTED_SNAPSHOT Failed" with extra info along the lines of "Error executing System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."

The reason for this is the database has its READ_COMMITTED_SNAPSHOT setting turned OFF before upgrading and does not turn it back ON before failing. Utilities 3e fails to function correctly, as does the IDE and the front end!

The database can become inaccessible in Sql Query Analyser / SSMS, preventing queries being ran against it. Taking the database offline then bringing it back online solves this problem.

What's required is to turn READ_COMMIT_SNAPSHOT back on. This is typically done by running this on the DB in question:

ALTER DATABASE <DATABASE_NAME> SET READ_COMMITTED_SNAPSHOT ON

However, this statement can fail to run correctly and endlessly run in Query Analyser, never completing. A better option (for Sql Server 2005 - i.e. 3e 2.5 and below) is:

IF(CHARINDEX('Microsoft SQL Server 2005',@@VERSION) > 0)
BEGIN
    DECLARE @sql VARCHAR(8000)
    SELECT @sql = '
    ALTER DATABASE ' + DB_NAME() + ' SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
    ALTER DATABASE ' + DB_NAME() + ' SET READ_COMMITTED_SNAPSHOT ON;
    ALTER DATABASE ' + DB_NAME() + ' SET MULTI_USER;'
    EXEC(@sql)
END

An IIS Reset may be needed after this, but after that all 3e systems should be running as before. The Update from within Utilities3e always seems to work the second time around.

No comments:

Post a Comment