sp_addremotelogin (Transact-SQL)sp_addremotelogin (Transact-SQL)

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions)

在本地服务器上添加新的远程登录 ID。Adds a new remote login ID on the local server. 这样,远程服务器就能够连接并执行远程过程调用。This enables remote servers to connect and execute remote procedure calls.

重要

后续版本的 Microsoft SQL Server 将删除该功能。This feature will be removed in a future version of Microsoft SQL Server. 请避免在新的开发工作中使用该功能,并着手修改当前还在使用该功能的应用程序。Avoid using this feature in new development work, and plan to modify applications that currently use this feature. 请改用链接服务器和链接服务器存储过程。Use linked servers and linked server stored procedures instead.

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

  
sp_addremotelogin [ @remoteserver = ] 'remoteserver'   
     [ , [ @loginame = ] 'login' ]   
     [ , [ @remotename = ] 'remote_name' ]  

参数Arguments

[ @remoteserver = ] \ "remoteserver"[ @remoteserver = ] 'remoteserver'
远程登录名所适用的远程服务器的名称。Is the name of the remote server that the remote login applies to. remoteserver 的值为 sysname,无默认值。remoteserver is sysname, with no default. 如果仅指定了 remoteserver ,则 remoteserver 上的所有用户将映射到本地服务器上具有相同名称的现有登录名。If only remoteserver is specified, all users on remoteserver are mapped to existing logins of the same name on the local server. 对于本地服务器而言,远程服务器必须是已知的。The server must be known to the local server. 可以使用 sp_addserver 来添加。This is added by using sp_addserver. remoteserver 上的用户连接到运行的本地服务器 SQL ServerSQL Server 以执行远程存储过程时,它们将作为本地登录名,该登录名与其在 remoteserver 上的登录名匹配。When users on remoteserver connect to the local server that is running SQL ServerSQL Server to execute a remote stored procedure, they connect as the local login that matches their own login on remoteserver. remoteserver 是启动远程过程调用的服务器。remoteserver is the server that initiates the remote procedure call.

[ @loginame = ] "login"[ @loginame = ] 'login'
SQL ServerSQL Server 本地实例上的用户的登录 ID。Is the login ID of the user on the local instance of SQL ServerSQL Server. login 的数据类型为 sysname,默认值为 NULL。login is sysname, with a default of NULL. 登录名 必须在本地实例上已经存在 SQL ServerSQL Serverlogin must already exist on the local instance of SQL ServerSQL Server. 如果指定 login ,则 remoteserver 上的所有用户将映射到该特定本地登录名。If login is specified, all users on remoteserver are mapped to that specific local login. remoteserver 上的用户连接到的本地实例 SQL ServerSQL Server 以执行远程存储过程时,它们将作为 登录名 进行连接。When users on remoteserver connect to the local instance of SQL ServerSQL Server to execute a remote stored procedure, they connect as login.

[ @remotename = ] 'remote_name'[ @remotename = ] 'remote_name'
远程服务器上的用户的登录 ID。Is the login ID of the user on the remote server. remote_name 的默认值为 sysname,默认值为 NULL。remote_name is sysname, with a default of NULL. remoteserver 上必须存在 remote_nameremote_name must exist on remoteserver. 如果指定 remote_name ,则特定用户 remote_name 会映射到本地服务器上的 登录名If remote_name is specified, the specific user remote_name is mapped to login on the local server. remoteserver 上的 remote_name 连接到的本地实例 SQL ServerSQL Server 以执行远程存储过程时,它将作为 登录名 进行连接。When remote_name on remoteserver connects to the local instance of SQL ServerSQL Server to execute a remote stored procedure, it connects as login. Remote_name 的登录 id 可以不同于远程服务器上的登录 id 登录名The login ID of remote_name can be different from the login ID on the remote server, login.

返回代码值Return Code Values

0(成功)或 1(失败)0 (success) or 1 (failure)

备注Remarks

若要执行分布式查询,请使用 sp_addlinkedsrvlogin。To execute distributed queries, use sp_addlinkedsrvlogin.

不能在用户定义的事务中使用 sp_addremotelogin。sp_addremotelogin cannot be used inside a user-defined transaction.

权限Permissions

只有 sysadmin 和 securityadmin 固定服务器角色的成员才能执行 sp_addremotelogin。Only members of the sysadmin and securityadmin fixed server roles can execute sp_addremotelogin.

示例Examples

A.A. 一对一映射Mapping one to one

以下示例在远程服务器 ACCOUNTS 和本地服务器具有相同的用户登录名时将远程名称映射到本地名称。The following example maps remote names to local names when the remote server ACCOUNTS and local server have the same user logins.

EXEC sp_addremotelogin 'ACCOUNTS';  

B.B. 多对一映射Mapping many to one

以下示例创建一个条目,该条目将来自远程服务器 ACCOUNTS 的所有用户都映射到本地登录 ID AlbertThe following example creates an entry that maps all users from the remote server ACCOUNTS to the local login ID Albert.

EXEC sp_addremotelogin 'ACCOUNTS', 'Albert';  

C.C. 使用显式一对一映射Using explicit one-to-one mapping

以下示例将来自远程服务器 Chris 上的远程用户 ACCOUNTS 的远程登录映射到本地用户 salesmgrThe following example maps a remote login from the remote user Chris on the remote server ACCOUNTS to the local user salesmgr.

EXEC sp_addremotelogin 'ACCOUNTS', 'salesmgr', 'Chris';  

另请参阅See Also

sp_addlinkedsrvlogin (Transact-SQL) sp_addlinkedsrvlogin (Transact-SQL)
sp_addlogin (Transact-SQL) sp_addlogin (Transact-SQL)
sp_addserver (Transact-sql) sp_addserver (Transact-SQL)
sp_dropremotelogin (Transact-sql) sp_dropremotelogin (Transact-SQL)
sp_grantlogin (Transact-SQL) sp_grantlogin (Transact-SQL)
sp_helpremotelogin (Transact-sql) sp_helpremotelogin (Transact-SQL)
sp_helpserver (Transact-SQL) sp_helpserver (Transact-SQL)
sp_remoteoption (Transact-sql) sp_remoteoption (Transact-SQL)
sp_revokelogin (Transact-SQL) sp_revokelogin (Transact-SQL)
系统存储过程 (Transact-SQL)System Stored Procedures (Transact-SQL)