zoukankan      html  css  js  c++  java
  • Distributed1:Linked Server 添加和删除

    A linked server allows for access to distributed, heterogeneous queries against OLE DB data sources. After a linked server is created by using sp_addlinkedserver, distributed queries can be run against this server. If the linked server is defined as an instance of SQL Server, remote stored procedures can be executed.

    1,添加Linked Server

    使用 sys.sp_addlinkedserver 添加Linked Server,除了必须在本地自定义一个Linked Server的Alias,还必须指定 Linked Server的Product name,Provider name,Data Source, location, provider string 和 catalog 参数。

    复制代码
    sp_addlinkedserver [ @server= ] 'server' [ , [ @srvproduct= ] 'product_name' ] 
         [ , [ @provider= ] 'provider_name' ]
         [ , [ @datasrc= ] 'data_source' ] 
         [ , [ @location= ] 'location' ] 
         [ , [ @provstr= ] 'provider_string' ] 
         [ , [ @catalog= ] 'catalog' ] 
    复制代码

    Arguments    

    @server= ] 'server'              

    Is the name of the linked server to create. server is sysname, with no default.

    @srvproduct= ] 'product_name'              

    Is the product name of the OLE DB data source to add as a linked server. product_name is nvarchar(128), with a default of NULL.

    @provider= ] 'provider_name'              

    Is the unique programmatic identifier (PROGID) of the OLE DB provider that corresponds to this data source. provider_name must be unique for the specified OLE DB provider installed on the current computer. provider_name is nvarchar(128), with a default of NULL; however, if provider_name is omitted, SQLNCLI is used. The OLE DB provider is expected to be registered with the specified PROGID in the registry.

    [@catalog= ] 'catalog'              

    Is the catalog to be used when a connection is made to the OLE DB provider. catalog is sysname, with a default of NULL. catalog is passed as the DBPROP_INIT_CATALOG property to initialize the OLE DB provider. When the linked server is defined against an instance of SQL Server, catalog refers to the default database to which the linked server is mapped

    Provider 需要安装,可以从SQL Server 的Linked Servers Catalog下查看已经安装的Providers。

    添加SQL Server 作为Linked Server,将@srvproduct 设置为 N'' 字符。

    复制代码
    --add linked server
    exec sys.sp_addlinkedserver @server= N'RemoteServerAlias'
    ,@srvproduct= N'' ,@provider= N'SQLNCLI' ,@datasrc= N'RemoteServerNameSQLServerInstanceName' ,@location= null ,@provstr= null ,@catalog= N'Remote_DB_Name'
    复制代码

    2,使用 sys.servers 查看添加的Linked Server

    sys.servers Contains a row per linked or remote server registered, and a row for the local server that has server_id = 0.

    When you create a linked or remote server, SQL Server creates a default login mapping to the public server role. This means that by default, all logins can view all linked and remote servers. To restrict visibility to these servers, remove the default login mapping by executing sp_droplinkedsrvlogin and specifying NULL for the locallogin parameter.

    select *
    from sys.servers
    where name=N'ExcelDataSource'

    3,使用 sys.sp_dropserver 删除Linked Server

    Syntax

    sp_dropserver [ @server = ] 'server' 
         [ , [ @droplogins = ] { 'droplogins' | NULL} ]

    @droplogins = 'droplogins' | NULL

    Indicates that related remote and linked server logins for server must also be removed if droplogins is specified. @droplogins is char(10), with a default of NULL.

    在删除Linked Server时,将login一起删除。

    EXEC sys.sp_dropserver @server=N'ExcelDataSource', @droplogins='droplogins'
    GO


    参考doc:

    MSDN:sp_addlinkedserver (Transact-SQL)

  • 相关阅读:
    TSINGSEE青犀视频云边端架构产品EasyNVR/EasyGBS/EasyDSS区别及应用场景介绍
    【解决方案】TSINGSEE青犀视频云边端架构产品如何实现明厨亮灶汇总直播方案?
    【开发记录】RTSP/GB28181/Ehome协议安防视频服务平台EasyCVR使用golang orm操作数据库及基本使用步骤
    TSINGSEE青犀视频云边端架构产品是如何实现视频流传输的?
    【开发记录】安防视频上云服务云平台EasyCVR部署之docker部署步骤参考说明
    TSINGSEE青犀视频+海康合作研发RTMP推流摄像头出现无法推流或无法上线的情况如何配置?
    VC中利用管道技术取得DOS或者命令行以及外部程序的执行结果
    系统程序员成长计划拥抱变化(下)
    系统程序员成长计划Write once, run anywhere(WORA)(下)
    KJava虚拟机hack笔记编译
  • 原文地址:https://www.cnblogs.com/xieyulin/p/7050656.html
Copyright © 2011-2022 走看看