zoukankan      html  css  js  c++  java
  • MSSQL 跨服器调用存储过程

    • A库
    • CREATE PROCEDURE [dbo].[A_P_Test]
      AS
      BEGIN
         SELECT * FROM dbo.A_LoadData
      END
    • B库  在B中调用A库存储过程 注:是同一服务器调用。 
    • CREATE PROCEDURE [dbo].[A_P_Test2]
      AS
      BEGIN
          declare @sql nvarchar(500);
          set @sql = N' exec AMACDB_TEST.dbo.A_P_Test ';
          exec  sp_executesql @sql
      END
    • A,B两个数据库,不在同一台服务器实例, 在B库的存储过程中,调用A库的存储过程

          B库

         

    CREATE PROCEDURE [dbo].[A_P_Test2]
    AS
    BEGIN
       declare @sql varchar(MAX);
       set @sql = N' exec OPENDATASOURCE(''SQLOLEDB'',''Data Source=192.168.120.13;User ID=sa;Password=sa'').AMACDB_TEST.dbo.A_P_Test ';
       exec  sp_executesql @sql
    END

    注:如果出现下面问题

    消息 15281,级别 16,状态 1,第 1 行
    
    SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries'
    
    because this component is turned off as part of the security configuration for this server.
    
    A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure.
    
    For more information about enabling 'Ad Hoc Distributed Queries',
    
    see "Surface Area Configuration" in SQL Server Books Online.

    解决方法如下:

    exec sp_configure 'show advanced options',1
    reconfigure
    exec sp_configure 'Ad Hoc Distributed Queries',1
    reconfigure
  • 相关阅读:
    关掉firefox(火狐)和palemoon地址栏自动加www.前缀功能【转】
    Maven入门指南(一)
    Linux 常用命令
    maven-编译速度优化
    monkeyscript
    GIT
    maven简介及基础使用
    使用xcrun打包iOS应用
    Mac系统下STF的环境搭建和运行
    npm介绍与cnpm介绍
  • 原文地址:https://www.cnblogs.com/liudabao123/p/5384397.html
Copyright © 2011-2022 走看看