简体   繁体   中英

BCP: Error Running BCP in SQL Server but not in cmd

I am able to run bcp commands on the command line, but unfortunately when trying in SQL Server, I see the following error:

Error = [Microsoft][SQL Server Native Client 11.0]Unable to open BCP host data-file

This is the code I use in SQL Server:

EXEC xp_cmdshell 'bcp "SELECT ''col1'', ''col2'' union all select col1, col2FROM [kat].[dbo].[Table_Data] WITH (NOLOCK)" queryout ''C:\Users\kata\exportFiles\FirstTestOutput.csv''  -t; -c -T' 

Could it be an error with the quotes " ' "?

Many thanks in advance,

Kat

'xp_cmdshell' has to run as "someone". It doesn't run as you. It runs as the "SQL Server service account". That is an account set up in a the "services applet". By default it's an account that won't have rights to your personal folders. So you either change this service account to have more rights or you only use folders that it has rights to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM