Home Forums SQL Server 2005 Administering sql server CONFIG statement cannot be used inside a user transaction RE: sql server CONFIG statement cannot be used inside a user transaction

  • 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