The SetOwner method reassigns ownership for a Microsoft® SQL Server™ database.
object.SetOwner( LoginName , [ TransferAliases ] , [ OverrideIfAlreadyUser ] )
Part | Description |
---|---|
object | Expression that evaluates to an object in the Applies To list. |
LoginName | String specifying an existing SQL Server login by name. |
TransferAliases | Optional. True or False as described in Settings. |
OverrideIfAlreadyUser | Optional. True or False as described in Settings. |
The TransferAliases argument is maintained for compatibility with earlier versions of SQL Server security relying on aliases to assign privilege. For database ownership privilege based on membership in the db_owner role, the argument can be ignored safely. Set TransferAliases by using:
Set OverrideIfAlreadyUser by using:
Reassigning ownership of a SQL Server database by using the SetOwner method requires appropriate privilege. The SQL Server login used for SQLServer object connection must be the current database owner or a member of the fixed role sysadmin.
HRESULT SetOwner(
SQLDMO_LPCSTR NewValue,
BOOL bTransferAliases = FALSE,
BOOL bOverrideIfAlreadyUser = FALSE);