孤立用户解决办法

解决方法:
    1.建立与孤立用户同名的登陆用户(密码随便),改变对象的属主
        sp_changeobjectowner [ @objname = ] 'object' , [ @newowner = ] 'owner'
    如:
         use authors
        exec sp_changeobjectowner 'authors', 'dbo';
        GO
    缺点:当需要修改的数据库对象很多时,麻烦!!
 
    2. sp_change_users_login 'Auto_Fix', 'test', NULL, 'testpassword'
      注:test为孤立用户名 testpassword为孤立用户密码
资料:
    sp_change_users_login (Transact-SQL) 将现有数据库用户映射到 SQL Server 登录名。
    注: sp_change_users_login 不能用于 Windows 主体创建的 SQL Server 登录名。

Changes the relationship between a Microsoft® SQL Server™ login and a SQL Server user in the current database.

Syntax

sp_change_users_login [@Action =] 'action' [,[@UserNamePattern =] 'user']
    [,[@LoginName =] 'login']

Arguments
[@Action =] 'action' Describes the action to be performed by the procedure. action is varchar(10), and can be one of these values.

 

Value Description Auto_Fix Links user entries in the sysusers table in the current database to logins of the same name in syslogins. It is recommended that the result from the Auto_Fix statement be checked to confirm that the links made are the intended outcome. Avoid using Auto_Fix in security-sensitive situations. Auto_Fix makes best estimates on links, possibly allowing a user more access permissions than intended.

user must be a valid user in the current database, and login must be NULL, a zero-length string (‘‘), or not specified.

Report Lists the users, and their corresponding security identifiers (SID), that are in the current database, not linked to any login.

user and login must be NULL, a zero-length string (‘‘), or not specified.

Update_One Links the specified user in the current database to login. login must already exist. user and login must be specified.
[@UserNamePattern =] 'user' Is the name of a SQL Server user in the current database. user is sysname, with a default of NULL. sp_change_users_login can only be used with the security accounts of SQL Server logins and users; it cannot be used with Microsoft Windows NT® users. [@LoginName =] 'login' Is the name of a SQL Server login. login is sysname, with a default of NULL.
Return Code Values

0 (success) or 1 (failure)

Result Sets
Column name Data type Description UserName sysname Login name. UserSID varbinary(85) Login security identifier.
Remarks

Use this procedure to link the security account for a user in the current database with a different login. If the login for a user has changed, use sp_change_users_login to link the user to the new login without losing the user’s permissions.

login cannot be sa, and user cannot be the dbo, guest, or INFORMATION_SCHEMA users.

sp_change_users_login cannot be executed within a user-defined transaction.

Permissions

Any member of the public role can execute sp_change_users_login with the Report option. Only members of the sysadmin fixed server role can specify the Auto_Fix option. Only members of the sysadmin or db_owner roles can specify the Update_One option.

Examples
A. Show a report of the current user to login mappings

This example produces a report of the users in the current database and their security identifiers.

EXEC sp_change_users_login 'Report'

  

B. Change the login for a user

This example changes the link between user Mary in the pubs database and the existing login, to the new login NewMary (added with sp_addlogin).

--Add the new login.

USE master

go

EXEC sp_addlogin 'NewMary'

go

  

--Change the user account to link with the 'NewMary' login.

USE pubs

go

EXEC sp_change_users_login 'Update_One', 'Mary', 'NewMary'


Refer:http://msdn2.microsoft.com/zh-cn/library/ms174378.aspx#

转载于:https://www.cnblogs.com/lanshh/archive/2007/02/08/644852.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值