3

我有

CONFIG 语句不能在用户事务中使用

运行下面的程序 2 时。有什么决议吗?谢谢。

程序#1:

CREATE PROC [dbo].[nz_test1]
as
   EXEC sp_configure 'show advanced option', 1
   RECONFIGURE WITH OVERRIDE
   EXEC sp_configure 'xp_cmdshell', 1
   EXEC sp_configure 'ad hoc distributed queries', 1  
   RECONFIGURE WITH OVERRIDE

select 1

程序#2:

create proc [dbo].[test_nz_tb3]
as
    create table #t (a varchar(2))

    insert into #t
           exec nz_test1
4

1 回答 1

3

显然(对我来说,无论如何),如果你被告知你不能做你想做的事情,你需要改变你的代码以避免做你不允许做的事情。特别是,您可能需要将配置/重新配置代码移到您在 INSERT 语句(那个nz_test1)中调用的过程之外,例如,移动到另一个存储过程。单独运行该代码,可能插入之前(这可能取决于您通过重新配置尝试实现的目标,您没有透露)。

所以,像这样的东西,也许:

CREATE PROCEDURE dbo.my_config
AS
    EXEC sp_configure 'show advanced option', 1;
    RECONFIGURE WITH OVERRIDE;
    EXEC sp_configure 'xp_cmdshell', 1;
    EXEC sp_configure 'ad hoc distributed queries', 1;
    RECONFIGURE WITH OVERRIDE;
GO
CREATE PROCEDURE dbo.nz_test1
AS
    SELECT 1 AS Value;
GO
CREATE PROCEDURE dbo.test_nz_tb3
AS
    EXEC dbo.my_config;
    CREATE TABLE #t (a varchar(10));
    INSERT INTO #t
        EXEC dbo.nz_test1;

Make sure you do not call test_nz_tb3 within a transaction either. Otherwise you'll need to call my_config outside test_nz_tb3, likely before the transaction where the latter is called.

于 2012-08-26T23:04:19.777 回答