Knowledge Base

User logons and permissions on a database may be incorrect after the database is restored

Article ID: 168001

Article Last Modified on 3/28/2006


APPLIES TO


This article was previously published under Q168001

SYMPTOMS

If a dump of a SQL Server user database is restored to a different SQL Server (such as a hot backup server) or to the same SQL Server after either rebuilding or reloading an old version of the master database, user logons and permissions on the database may be incorrect.

This problem may reveal itself in several ways:
  • While logging on to a 6.x server, users may receive the following error:
    Msg 4002, Level 14, State 1, Server Microsoft SQL Server, Line 0
    Login failed
    DB-Library: Login incorrect.
  • While logging on to a 7.0 server, users may receive the following error:
    Msg 18456, Level 14, State 1,
    Login failed for user '%ls'.
  • While trying to access objects within the database, users may receive the following error:
    Msg 229, Level 14, State 1
    %s permission denied on object %.*s, database %.*s, owner %.*s
  • While attempting to create a login and grant access to the restored database, or add the user to the database, the following error may be received:
    Microsoft SQL-DMO (ODBC SQLState: 42000) Error 15023: User or role '%s' already exists in the current database.
  • Users may have permissions on objects for which they previously did not.

CAUSE

User logon information is stored in the syslogins table in the master database. By changing servers, or by altering this information by rebuilding or restoring an old version of the master database, the information may be different from when the user database dump was created. If logons do not exist for the users, they will receive an error indicating "Login failed" while attempting to log on to the server. If the user logons do exist, but the SUID values (for 6.x) or SID values (for 7.0) in master..syslogins and the sysusers table in the user database differ, the users may have different permissions than expected in the user database.

Note If you are using Microsoft SQL Server 2005, the syslogins table and the sysusers table are implemented as compatibility views. These views are sys.syslogins and sys.sysusers. For more information about compatibility views, see the "Compatibility Views (Transact-SQL)" topic in SQL Server 2005 Books Online.

WORKAROUND

To work around this problem, do any of the following:

Keywords: kbprb kbusage KB168001