在视图中调用存储过程,需要用到OPENROWSET 函数,在使用OPENROWSET函数时需要开启 Ad Hoc Distributed Queries 组件
如果为了网站和数据安全不建议使用此方式。
Create VIEW ViewRpVmsToken --创建视图
AS
SELECT *
FROM OPENROWSET(
'SQLNCLI', ---DBlink
'DRIVER={SQL Server};
SERVER=192.168.2.12;UID=sa;PWD=123456;Trusted_Connection=no',
'SET FMTONLY OFF;SET NOCOUNT ON;EXEC TR_E7.dbo.sp_RpVmsToken') --存储过程名称
go
--开启Ad Hoc Distributed Queries组件,在sql查询编辑器中执行如下语句:
EXEC sp_configure 'show advanced options',1
RECONFIGURE
EXEC sp_configure 'Ad Hoc Distributed Queries',1
RECONFIGURE
--关闭Ad Hoc Distributed Queries组件,在sql查询编辑器中执行如下语句:
EXEC sp_configure 'Ad Hoc Distributed Queries',0
RECONFIGURE
EXEC sp_configure 'show advanced options',0
RECONFIGURE
