Hi,
I’m having problems dropping a user this is my code:
Public Function DropUser() As Boolean
Dim conn As New ServerConnection("STATION01\SQLEXPRESS", wContainer.Username, wContainer.Password)
Dim myServer As New Server(conn)
Dim myDatabase As Database = myServer.Databases("VideoDB")
If myServer.Logins.Contains(“username”) Then
Dim db_user As New User(myDatabase, “username”)
db_user.Login = “username”
db_user.Drop()
Dim db_login As New Login(myServer, “username”)
db_login.Drop()
Return True
Else
Return False
End If
End Function
OK, whats the error message ? For the case that the user has a schema assigned you will first have to drop the schema or put in another owner for the schema.HTH, Jens K. Suessmeyer.
http:://www.sqlserver2005.de|||
If you want to ensure you've got the user/login out of all databases try this code (after you instantiate myServer):
Dim dbColl As DatabaseCollection
Dim dbCurrent As Database
Dim schColl As SchemaCollection
Dim schClean As Schema
Dim usrColl As UserCollection
Dim usrClean As User
Dim logColl As LoginCollection
Dim logClean As New Login
dbColl = myServer.Databases
For Each dbCurrent In dbColl
If Not dbCurrent.IsDatabaseSnapshot Then
schColl = dbCurrent.Schemas
schClean = schColl.Item("username")
If Not (schClean Is Nothing) Then
schClean.Drop()
End If
usrColl = dbCurrent.Users
usrClean = usrColl.Item("username")
If Not (usrClean Is Nothing) Then
usrClean.Drop()
End If
End If
Next
logColl = srvMgmtServer.Logins
logClean = logColl.Item("username")
If Not (logClean Is Nothing) Then
logClean.Drop()
End If
This will remove all the schema and user from every database used by this login, then drop the login.
|||Hi,
The error is:
Drop failed for User ‘username’
|||Thanks a lot....
No comments:
Post a Comment