SQL Server troubleshooting topics seem to be the most searched for in this blog. In continuation to this, blog for today is also inspired with one such error message. Some time back I have written below blog which talks about the upgrade script mode of SQL Server: SQL SERVER – Login Failed For User – Reason Server is in Script Upgrade Mode
One of the readers reached out to me with below error in ERRORLOG
spid9s Script level upgrade for database ‘master’ failed because upgrade step ‘sqlagent100_msdb_upgrade.sql’ encountered error 2714, state 6, severity 25. This is a serious error condition which might interfere with regular operation and the database will be taken offline. If the error happened during upgrade of the ‘master’ database, it will prevent the entire SQL Server instance from starting. Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion.
The interesting errors are:
- There is already an object named ‘DatabaseMailUserRole’ in the database.
- CREATE SCHEMA failed due to previous errors
If we look at sqlagent100_msdb_upgrade.sql which is mentioned in ERRORLOG, below is the place of failure.
EXECUTE msdb.dbo.sp_droprole @rolename = N'DatabaseMailUserRole' EXECUTE msdb.dbo.sp_addrole @rolename = N'DatabaseMailUserRole'
Looking at error message, we have some issues with DatabaseMailUserRole schema.
- In SSMS, we went to system databases > msdb > Security > Roles > Database Roles but we didn’t see DatabaseMailUserRole under it. So we ran the following query to double check and no result was returned:
SELECT * FROM msdb.dbo.sysusers WHERE (name = N'DatabaseMailUserRole')
So, we verified that “DatabaseMailUserRole” didn’t exist in the MSDB.
- But if we run the following query to check the schema we found the “DatabaseMailUserRole” exists:
select * from sys.schemas
- From above, we could see the “DatabaseMailUserRole” schema is indeed orphaned now as no user is associated with it.
At this point, we have two options to resolve this issue:
- Drop the “DatabaseMailUserRole” schema
- Create the “DatabaseMailUserRole” user and made it as the owner of “DatabaseMailUserRole” schema
We used second option to fix the orphaned schema by the script below:
USE [msdb] GO CREATE ROLE [DatabaseMailUserRole] AUTHORIZATION [dbo] GO USE [msdb] GO ALTER AUTHORIZATION ON SCHEMA::[DatabaseMailUserRole] TO [DatabaseMailUserRole] GO
Now, bigger question is how do we do it if SQL is not getting started? Well, have a look at trace flag 902. Here is the way to start SQL with trace flag. In below, SQL2014 is the name of my instance.
NET START MSSQL$SQL2014 /T902
Have you encountered script upgrade failure? How did you fix them?
Reference: Pinal Dave (https://blog.sqlauthority.com)