Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I want a query or stored proc to retrieve the result set of a query into a Datafile.
I have tried using bcp which throws error as mentioned below:


SQL
EXEC master..xp_cmdshell 'bcp "select
USERID_FK FROM ADM_USERROLES" queryout "D:\bcptest.txt" -T -c -t,'



for the above query I'm getting the error as

The EXECUTE permission was denied on the object 'xp_cmdshell', database 'mssqlsystemresource', schema 'sys'.


Please suggest what can I do...


Thanks & Regards,
Mathi.
Posted
Comments
[no name] 3-Jul-13 8:39am    
Well my suggestion would be to give "execute" permission to 'xp_cmdshell'

1 solution

MSDN:
Because malicious users sometimes attempt to elevate their privileges by using xp_cmdshell, xp_cmdshell is disabled by default. Use sp_configure or Policy Based Management to enable it. For more information, see xp_cmdshell Server Configuration Option.


xp_cmdshell (Transact-SQL)[^]
SQL SERVER – Enable xp_cmdshell using sp_configure[^]
 
Share this answer
 
Comments
Adarsh chauhan 5-Jul-13 2:44am    
links you provided are really very helpful.. nicely explained.. +5 for providing these links.
Maciej Los 5-Jul-13 11:10am    
You're welcome ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900