User already exists in the current database but without LOGIN

From: JJA (johna_at_cbmiweb.com)
Date: 01/26/05


Date: 26 Jan 2005 09:56:00 -0800

I upgraded my SQL Server 7.0 database, MYPROD, by detaching it from
SERVERNT, copying all its NT files to my new SERVER2003, and then I
EXECUTEd sp_attach_db to make it known to my default instance of SQL
Server 2000 (running on Windows Server 2003).

Thru Ent Manager, I notice that the Users entry for this database shows
MYWEBUSER as the USERNAME, <NONE> for the LOGIN name, and when I click
on the entry in the grid, the permissions are checked for PUBLIC and
DBO (both of which I want).

I have a perfectly good LOGIN called MYWEBUSER already in place on
SERVER2003 (and also on the old SERVERNT) but somehow in the process of
copying the files the relationship of this USER to a LOGIN has not been
copied over (i.e. this user entry has nothing for LOGIN).

So I tried this:

USE MYPROD
GO
EXEC sp_grantdbaccess @loginame = 'mywebuser'

Server: Msg 15023, Level 16, State 1, Procedure sp_grantdbaccess, Line
147
User or role 'mdwebuser' already exists in the current database.

I've looked around a lot and cannot seem to find how to script this
out. I am trying to avoid:
a. manual DELETE of the USER entry from MYPROD
b. manual visit to LOGINs, click on MYWEBUSER, and click of MYPROD
database
(step b seems to add MYWEBUSER into MYPROD with MYWEBUSER as a valid
LOGIN)

I know USER entry is different from the LOGIN entry. Is my problem due
to the fact that they are named the same? I can fix this manually but
would like to build a script to be run after this COPY with UPGRADE
operation. Thank you in advance for help.



Relevant Pages

  • Re: Install MSDE w/ MSDE Depl.Toolkit. What permissions when using Win Auth?
    ... I created a login using Enterprise Manager on SQL Server on my server. ... Database Access tab I ticked the tick box for the database that I ... Now when my user installed the MSDE database on his machine locally, ...
    (microsoft.public.sqlserver.msde)
  • Re: SQL Server 2005 Express Remote connection
    ... I have also deleted the login for Fred from the list of users for my ... So Fred no longer exists as a login or as a user in the SQL Server setup. ... the database? ...
    (microsoft.public.sqlserver.server)
  • Re: Installation OK, but cant connect
    ... > created an access database. ... SQL Server authentication is "client" independent.... ... connections or SQL Server authenticated connections... ... which authenticate user's login at the windows login step... ...
    (microsoft.public.sqlserver.msde)
  • Re: Moving a database to another server
    ... onto a server at home. ... The database has a user that has public, db_owner, ... SQL Server login or a Windows login. ...
    (microsoft.public.sqlserver.server)
  • Re: Setting up Linked server to MsAccess
    ... At the server level I have added my windows user group ... At the database level I have added my Server login ...
    (microsoft.public.sqlserver.security)