Tuesday, October 9, 2018

Upgrade Read-only Mode Databases on a SQL Server

Recently I upgraded my SQL server to SQL Server 2017. Everything went well.

But today when I tried to open a read-only mode database, I got an error:

Cannot open database 'DatabaseName' version 782. Upgrade the database to the latest version. (Microsoft SQL Server, Error: 946)

The database could not be detached. When I tried to detach it, the same error occured. I could not view the database's properties, either, because of the same error.

Nothing could be done on this read-only database, it seemed. I did not try to delete it, since I still wanted to keep the data.

Some google results suggested that the file access permissions could be the problem. Not in my case. The database files were fully accessible, both by the SQL sever process and myself.

The solution turned out to be very simple. All I needed to do was to run the following SQL script:

USE master; 
GO 
ALTER DATABASE DatabaseName
SET READ_WRITE; 
GO

When I ran this script, SQL server automatically started upgrading my database:
Converting database 'DatabaseName' from version 782 to the current version 869. Database 'DatabaseName' running the upgrade step from version 782 to version 801.
Database 'DatabaseName' running the upgrade step from version 801 to version 802.
Database 'DatabaseName' running the upgrade step from version 802 to version 803.
Database 'DatabaseName' running the upgrade step from version 803 to version 804.
Database 'DatabaseName' running the upgrade step from version 804 to version 805.
Database 'DatabaseName' running the upgrade step from version 805 to version 806.
Database 'DatabaseName' running the upgrade step from version 806 to version 807.
Database 'DatabaseName' running the upgrade step from version 807 to version 808.
Database 'DatabaseName' running the upgrade step from version 808 to version 809.
Database 'DatabaseName' running the upgrade step from version 809 to version 810.
Database 'DatabaseName' running the upgrade step from version 810 to version 811.
Database 'DatabaseName' running the upgrade step from version 811 to version 812.
Database 'DatabaseName' running the upgrade step from version 812 to version 813.
Database 'DatabaseName' running the upgrade step from version 813 to version 814.
Database 'DatabaseName' running the upgrade step from version 814 to version 815.
Database 'DatabaseName' running the upgrade step from version 815 to version 816.
Database 'DatabaseName' running the upgrade step from version 816 to version 817.
Database 'DatabaseName' running the upgrade step from version 817 to version 818.
Database 'DatabaseName' running the upgrade step from version 818 to version 819.
Database 'DatabaseName' running the upgrade step from version 819 to version 820.
Database 'DatabaseName' running the upgrade step from version 820 to version 821.
Database 'DatabaseName' running the upgrade step from version 821 to version 822.
Database 'DatabaseName' running the upgrade step from version 822 to version 823.
Database 'DatabaseName' running the upgrade step from version 823 to version 824.
Database 'DatabaseName' running the upgrade step from version 824 to version 825.
Database 'DatabaseName' running the upgrade step from version 825 to version 826.
Database 'DatabaseName' running the upgrade step from version 826 to version 827.
Database 'DatabaseName' running the upgrade step from version 827 to version 828.
Database 'DatabaseName' running the upgrade step from version 828 to version 829.
Database 'DatabaseName' running the upgrade step from version 829 to version 830.
Database 'DatabaseName' running the upgrade step from version 830 to version 831.
Database 'DatabaseName' running the upgrade step from version 831 to version 832.
Database 'DatabaseName' running the upgrade step from version 832 to version 833.
Database 'DatabaseName' running the upgrade step from version 833 to version 834.
Database 'DatabaseName' running the upgrade step from version 834 to version 835.
Database 'DatabaseName' running the upgrade step from version 835 to version 836.
Database 'DatabaseName' running the upgrade step from version 836 to version 837.
Database 'DatabaseName' running the upgrade step from version 837 to version 838.
Database 'DatabaseName' running the upgrade step from version 838 to version 839.
Database 'DatabaseName' running the upgrade step from version 839 to version 840.
Database 'DatabaseName' running the upgrade step from version 840 to version 841.
Database 'DatabaseName' running the upgrade step from version 841 to version 842.
Database 'DatabaseName' running the upgrade step from version 842 to version 843.
Database 'DatabaseName' running the upgrade step from version 843 to version 844.
Database 'DatabaseName' running the upgrade step from version 844 to version 845.
Database 'DatabaseName' running the upgrade step from version 845 to version 846.
Database 'DatabaseName' running the upgrade step from version 846 to version 847.
Database 'DatabaseName' running the upgrade step from version 847 to version 848.
Database 'DatabaseName' running the upgrade step from version 848 to version 849.
Database 'DatabaseName' running the upgrade step from version 849 to version 850.
Database 'DatabaseName' running the upgrade step from version 850 to version 851.
Database 'DatabaseName' running the upgrade step from version 851 to version 852.
Database 'DatabaseName' running the upgrade step from version 852 to version 853.
Database 'DatabaseName' running the upgrade step from version 853 to version 854.
Database 'DatabaseName' running the upgrade step from version 854 to version 855.
Database 'DatabaseName' running the upgrade step from version 855 to version 856.
Database 'DatabaseName' running the upgrade step from version 856 to version 857.
Database 'DatabaseName' running the upgrade step from version 857 to version 858.
Database 'DatabaseName' running the upgrade step from version 858 to version 859.
Database 'DatabaseName' running the upgrade step from version 859 to version 860.
Database 'DatabaseName' running the upgrade step from version 860 to version 861.
Database 'DatabaseName' running the upgrade step from version 861 to version 862.
Database 'DatabaseName' running the upgrade step from version 862 to version 863.
Database 'DatabaseName' running the upgrade step from version 863 to version 864.
Database 'DatabaseName' running the upgrade step from version 864 to version 865.
Database 'DatabaseName' running the upgrade step from version 865 to version 866.
Database 'DatabaseName' running the upgrade step from version 866 to version 867.
Database 'DatabaseName' running the upgrade step from version 867 to version 868.
Database 'DatabaseName' running the upgrade step from version 868 to version 869.
What a surprise.