Groups | Blog | Home
all groups > sql server programming > february 2004 >

sql server programming : Problems trying to delete an SQL Server login with access to 2 different databases


Kirk Graves
2/21/2004 4:47:13 PM
First, you only need to execute sp_DropLogin once, as it is general to SQL
Server instance, not to the db.
Second, I would verify that the login is actually being dropped.
here is a list of reasons you could check if the login is not being dropped
(straight from books on line)

a.. login owns an existing database.
a.. login owns jobs in the msdb database.
a.. login is currently in use and connected to SQL Server

Kirk Graves
KRGIT Software

[quoted text, click to view]

Marco Napoli
2/21/2004 6:41:54 PM
I am trying to delete a user from SQL Server which as access to 2 different
database in the same SQL Server.
What is the correct way of Deleting an SQL Server login?
The below runs, but when I try to recreate another user with the name c it
says its already created? I am sure I am not doing the Delete SQL Server
commands....

use DB1
exec sp_dropuser 'c'
use DB2
exec sp_dropuser 'c'
use DB1
exec sp_droplogin 'c'
use DB2
exec sp_droplogin 'c'

Thanks
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org

JT Lovell
2/21/2004 10:13:50 PM
I think you're seeing a problem I get a lot. Here's what my problem is and
the solution I use, perhaps it will help you.

I get a problem similar to this when I backup and restore a database under a
different name. I end up with 2 databases thinking they have a user X, but
the SQL server only thinks user X has access to the one database. To fix
this, I end up having to delete the user from SQL server and in the second
database, and then recreate it and give access to both databases.

Here's the process (SQL Server 2000):

1. In Enterprise Manager, right-click the SQL server and select properties.
2. On the Server Settings tab, check the box under Server behavior that
says, "Allow modifications to be made directly to the system catalogs."
3. Click OK to exit SQL Server Properties.
4. Delete the user from the SQL Server by removing from
[ServerName]>Security>Logins
5. Verify that each database no longer shows that user under
[ServerName]>Databases>[DatabaseName]>Users
6. If the user still shows up, try to remove via the GUI. If it gives an
error continue on to #7
7. Open [ServerName]>Databases>[DatabaseName]>Tables and right-click the
"sysusers" table. Select Open Table>Return all rows
8. Find the row with the matching "name" to the user you are trying to
delete, and delete it.
9. Try to recreate the user normally.

I'm sure you can do this via SQL scripts as well, but I generally do this in
the GUI.

--
JT Lovell

[quoted text, click to view]

Marco Napoli
2/23/2004 3:31:57 PM
Unfortunatly I need to figure out how to delete a login from a SQL Script.

Thanks
Marco


[quoted text, click to view]

AddThis Social Bookmark Button