March 31, 2021 at 5:57 am
Hello,
I am facing the below issue.
I run a bcp queryout command (select field names union all select * from mytable) from SQL server (-T windows authentication) and I am getting the error as seen in the attachment.
When I execute the command from CMD, it is being executed successfully.
Any ideas?
Thank you.
March 31, 2021 at 7:02 am
This was removed by the editor as SPAM
March 31, 2021 at 7:06 am
Thank you Rajattechno for your answer.
I don't think it has to do with a damaged or corrupted installation, but maybe a permission issue or something like that.
Any other ideas?
Thank you.
March 31, 2021 at 7:43 am
can you post the code here - without it we can't tell you what you are doing wrong - but normally its a small thing like missing quotes somewhere.
March 31, 2021 at 9:25 am
we actually need your full bcp command to figure out what's going on.
REM Create_FMT_files
bcp "[yourdb].[yourschema].[yourtableorview]" format NUL -fD:\BCP\BCPExp\yourdb_yourschema_yourtableorview.fmt -S yoursqlserver -U sqluser-P sqlpwd -n -o D:\BCP\BCPExp\yourdb_yourschema_yourtableorview_fmt.log
REM Export_Data_files
bcp "[yourdb].[yourschema].[yourtableorview]" out D:\BCP\BCPExp\yourdb_yourschema_yourtableorview.bcp -fD:\BCP\BCPExp\yourdb_yourschema_yourtableorview.fmt -S yoursqlserver -U sqluser-P sqlpwd -CRAW -o D:\BCP\BCPExp\yourdb_yourschema_yourtableorview_bcpOUT.log
REM Import data
bcp "[yourTARGETdb].[yourschema].[yourtableorview]" in D:\BCP\BCPExp\yourdb_yourschema_yourtableorview.bcp -fD:\BCP\BCPExp\yourdb_yourschema_yourtableorview.fmt -S TARGETSQLSERVER -T -CRAW -k -U sqluser-P sqlpwd -h"TABLOCK,CHECK_CONSTRAINTS" -o D:\BCP\BCPExp\yourdb_yourschema_yourtableorview_LOAD.log
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
March 31, 2021 at 10:10 am
It's not syntax error, cause as I said the command is running normally from CMD.
The code is above.
declare @cmd nvarchar(4000)
set @cmd = 'bcp "select ''Field1'', ''Field2'' union all select Field1, Field2 from [mydatabase].dbo.[mytable]" QUERYOUT "\\file_path\file_name.csv" -c -C1253 -t ";" -r \n -S Servername -T'
exec master..xp_cmdshell @cmd
Thanks.
March 31, 2021 at 2:54 pm
Well does the account running SQL Server have access to the filepath?
March 31, 2021 at 3:13 pm
Yes, it has access to this path. Also, I have given access to the bcp.exe for the SQL service and still the problem remains.
March 31, 2021 at 6:45 pm
hum. based on the output you gave us you are executing a Sybase BCP command - so either you not using SQL Server or the server you are executing the bcp has or had a install of Sybase and their BCP is being executed instead of the SQL Server version of it.
see http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc20155.1500/html/newfesd/newfesd109.htm for syntax of Sybase BCP
March 31, 2021 at 6:50 pm
Are you running the bcp command as you show it (i.e. spread over 2 lines)? Try to put it all on one line to see if it makes a difference
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
March 31, 2021 at 7:07 pm
@frederico_fonseca It's not a sybase command, it's a classic dos command executed through SQL server with the xp_cmdshell command.
@mike01 I am executing the command in one line, as it should be.
March 31, 2021 at 7:13 pm
@frederico_fonseca It's not a sybase command, it's a classic dos command executed through SQL server with the xp_cmdshell command.
as you didn't read what I said, neither the link, please issue the following command then and give us the output
exec master..xp_cmdshell 'bcp -v'
March 31, 2021 at 8:11 pm
Of course I read what you said, and I checked the link.
As I said, it has nothing to do with sybase bcp command, and also the specific command brings an error too.
March 31, 2021 at 8:19 pm
what error?
in SQL Server BCP the command works fine and outputs the version of BCP - on other versions of BCP (such as yours) it may error but without its output we don't even know what may be happening
and you can try it out on your own command line to see what the output should be (6 lines, 3 are empty)
EDIT: having a sybase client installed on the server will cause the same issue as Sybase bcp will be installed as part of the client and if this one is on the PATH before the sql server version it will be picked up.
Viewing 15 posts - 1 through 15 (of 22 total)
You must be logged in to reply to this topic. Login to reply