[转] sql server 跨数据库调用存储过程
A庫(kù)存儲(chǔ)過(guò)程:
create PROCEDURE [dbo].[spAAAForTest] ( @UserName nvarchar(20) =null ,@LoginPwd nvarchar(60) =null ) AS BEGINselect N'A' AS a, N'B' AS B, N'C' AS C;END同一臺(tái)服務(wù)器實(shí)例,A,B兩個(gè)數(shù)據(jù)庫(kù), 在B庫(kù)的存儲(chǔ)過(guò)程中,調(diào)用A庫(kù)的存儲(chǔ)過(guò)程
B庫(kù):
ALTER PROCEDURE [dbo].[spAAAForTest2] ( @UserName nvarchar(20) =null ,@LoginPwd nvarchar(60) =null ) AS BEGINdeclare @sql nvarchar(500);set @sql = N' exec DB_A.dbo.spAAAForTest ';exec sp_executesql @sqlEND?
A,B兩個(gè)數(shù)據(jù)庫(kù),不在同一臺(tái)服務(wù)器實(shí)例, 在B庫(kù)的存儲(chǔ)過(guò)程中,調(diào)用A庫(kù)的存儲(chǔ)過(guò)程
B庫(kù):
ALTER PROCEDURE [dbo].[spAAAForTest2] ( @UserName nvarchar(20) =null ,@LoginPwd nvarchar(60) =null ) AS BEGINdeclare @sql nvarchar(500);set @sql = N' exec OPENDATASOURCE(''SQLOLEDB'',''Data Source=SERVER-123\MSSQL2008R2;User ID=sa;Password=sa'').DB_A.dbo.spAAAForTest ';exec sp_executesql @sqlEND?
?
?
--------------- 在跨服務(wù)器調(diào)用時(shí),所使用OPENDATASOURCE 遭遇如下信息時(shí)
消息 15281,級(jí)別 16,狀態(tài) 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.
?
通過(guò)如下方式進(jìn)行設(shè)置:
exec sp_configure 'show advanced options',1 reconfigure exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure?
?
轉(zhuǎn)自:freeliver54??sql server 跨數(shù)據(jù)庫(kù)調(diào)用存儲(chǔ)過(guò)程???(侵刪)
轉(zhuǎn)載于:https://www.cnblogs.com/hydor/p/5737380.html
總結(jié)
以上是生活随笔為你收集整理的[转] sql server 跨数据库调用存储过程的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 语言魅力
- 下一篇: 【转】小白级的CocoaPods安装和使