I got
CONFIG statement cannot be used inside a user transaction
when running procedure 2 below. Any resolution? Thanks.
Procedure #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
Procedure #2:
create proc [dbo].[test_nz_tb3]
as
create table #t (a varchar(2))
insert into #t
exec nz_test1
Apparently (to me, anyway), if you are told that you can’t do what you are trying to do, you need to change your code to avoid doing what you aren’t allowed to. In particular, you likely need to move the configuration/reconfiguration code outside the procedure you are calling in the INSERT statement (the
nz_test1one), to another stored procedure, for instance. Run that code separately, probably before the insert (that may depend on what you are trying to achieve with that reconfiguration, which you aren’t revealing).So, something like this, perhaps:
Make sure you do not call
test_nz_tb3within a transaction either. Otherwise you’ll need to callmy_configoutsidetest_nz_tb3, likely before the transaction where the latter is called.