Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sql server CONFIG statement cannot be used inside a user transaction


sql server CONFIG statement cannot be used inside a user transaction

Author
Message
nzhang6666
nzhang6666
Valued Member
Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)

Group: General Forum Members
Points: 55 Visits: 309
I got 'CONFIG statement cannot be used inside a user transaction' when running proc 2 below. Any resolution? Thanks. (sql server 2005)

proc 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
proc 2:

create proc [dbo].[test_nz_tb3]
as

create table #t (a varchar(2))

insert into #t
exec nz_test1
durai nagarajan
durai nagarajan
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1107 Visits: 2771
what are you trying to do, are you trying to save the output of configuration sp's in the table and do some manipulations?

Regards
Durai Nagarajan
Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8235 Visits: 14368
Use a return code.

Zero typically means 'no error' and non-zero typically means 'problem occurred'.

-- proc 1:

ALTER PROC [dbo].[nz_test1]
AS
BEGIN TRY
EXEC sp_configure
'show advanced option',
1
RECONFIGURE WITH OVERRIDE
EXEC sp_configure
'xp_cmdshell',
0
EXEC sp_configure
'ad hoc distributed queries',
0
RECONFIGURE WITH OVERRIDE

RETURN 0
END TRY
BEGIN CATCH
RETURN 1
END CATCH
GO

--proc 2:

ALTER PROC [dbo].[test_nz_tb3]
AS
DECLARE @return_value INT;
EXEC @return_value = dbo.nz_test1
SELECT CASE @return_value
WHEN 0 THEN 'Success'
ELSE 'Fail'
END
GO

EXEC [dbo].[test_nz_tb3]
GO



__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47206 Visits: 44367
Just one point.

Reconfigure With Override tells SQL not to check that the values you've specified are sensible and valid values. It allows you to set options to values that will cause problems.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


nzhang6666
nzhang6666
Valued Member
Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)

Group: General Forum Members
Points: 55 Visits: 309
Thanks for the replies, I was on holiday so didn't come here.

Actually in my first proc (nz_test1) I just want to make sure to turn on 'xp_cmdshell' and 'ad hoc distributed queries'. Then following queries will generate a result set.
The second proc (test_nz_tb3) willl then used the result set. So there has to be the

insert into #t
exec nz_test1

to get the result set from the first proc.

I know if the insert statement is removed then everything is fine.

So maybe I should put the 'xp_cmdshell' and 'ad hoc distributed queries' code in test_nz_tb3? Or maybe just set these separately (E.g. run it only once as a administration task), since these seem not relevant to the main logic of the proc. But if these are accidently turned off by someone else then the proc will break. I am just wondering what is the best practice. Thanks.
Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8235 Visits: 14368
nzhang6666 (8/28/2012)
Thanks for the replies, I was on holiday so didn't come here.

Actually in my first proc (nz_test1) I just want to make sure to turn on 'xp_cmdshell' and 'ad hoc distributed queries'. Then following queries will generate a result set.
The second proc (test_nz_tb3) willl then used the result set. So there has to be the

insert into #t
exec nz_test1

to get the result set from the first proc.

I know if the insert statement is removed then everything is fine.

You do not need to return a resultset. Did you look at the code I provided showig how to use a return code?

So maybe I should put the 'xp_cmdshell' and 'ad hoc distributed queries' code in test_nz_tb3? Or maybe just set these separately (E.g. run it only once as a administration task), since these seem not relevant to the main logic of the proc. But if these are accidently turned off by someone else then the proc will break. I am just wondering what is the best practice. Thanks.


If you're worried and are guarding from someone disabling xp_cmdshell then you have bigger issues than just your proc failing. It means you do not have control over your instance, and that you have little faith in the ones that do have control to check to see if anyone is using the feature before disabling it.

If you;re that concerned maybe we should discuss the need a bit more. Security Best Practices say not to use xp_cmdshell unless it is absolutely needed. Are you sure you need it? Can what you're trying to do be done some other way without enabling xp_cmdshell, for example with a Windows batch script or PowerShell script?

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
nzhang6666
nzhang6666
Valued Member
Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)

Group: General Forum Members
Points: 55 Visits: 309
Hi opc, I saw your code. But actually I was not just seeing the results of the config statements. There are more logic after the config statements, which I didn't put it here because they are not relevant to this problem. And I am just a developer new to my current company, not a DBA, so that's why I want to make sure my code won't break without relying on other people. I ended up putting the config statements in a separate proc (say usp_config). So in my 'outer ' proc, the usp_config is called first then I can run the
insert into #temp exec 'inner proc'

Thanks.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search