显示标签为“recognized”的博文。显示所有博文
显示标签为“recognized”的博文。显示所有博文

2012年2月25日星期六

BCP bcp is not recognized

Hi
I am a bit new to SQL Server so please help me
I am trying to run a simple task at a customer but it doesn't work.
bcp isn't recognized.

I'm running this:
exec xp_cmdshell 'bcp "SELECT top 10 * FROM pubs..authors " queryout "C:\Temp\hej.txt" -c -S [ServerName] -T'
and it givs me this errormess.
'bcp' is not recognized as an internal or external command,

It works fine for me when I'm running it on my computer.

Can anyone please inform me what I'm missing. I haven't got a clue.
BR
CiottiIs the folder where bcp.exe is in your path (system) ?|||Hai ciotti,

Where is the "hej.txt" file located ? In the server hard disk or in the client machine hard disk.

When u use xp_cmdshell extended stored procdure, the command will be executed in the server and not in the client machine.

You have said that it works fine in ur system. So did u executed 'bcp' from the command line or using xp_cmdshell ?

If ur machine is the server and u executed it in the command prompt, then fine, u have to include the path of "bcp" in the System PATH.

Hope this helps u...Do let us know what happened.|||You were right. Someone had messed up the system path.
(Don't know who, and I dont care ;) )

Now the bcp command works.
The customer is happy and that makes me happy.
Thank you all for your quick answers.

/Ciotti

2012年2月18日星期六

BCP - File generate and name HELP

Hi All
I am trying to generate and name a file with the
following syntax : but get Error: 'bcpSelect' is not
recognized as an internal or external command,
DECLARE @.A char(100)
DECLARE @.str varchar(200)
DECLARE @.B Char(100)
DECLARE @.Con varchar(500)
Select @.Con = DataCon from FileNameCreate
Select @.A = SerialNo from FileNameCreate
Select @.B = 'Select * from FileNameCreate + +'
Select @.str='bcp' + @.B + 'queryout c:\Lut' + @.A + '.txt -
c -Usa -P -SUKLUN005\UKLUS0004H'
EXEC master..XP_cmdshell @.str"Brian" <anonymous@.discussions.microsoft.com> wrote in message
news:09e701c3a606$1561a040$a301280a@.phx.gbl...
> Hi All
> I am trying to generate and name a file with the
> following syntax : but get Error: 'bcpSelect' is not
> recognized as an internal or external command,
>
> DECLARE @.A char(100)
> DECLARE @.str varchar(200)
> DECLARE @.B Char(100)
> DECLARE @.Con varchar(500)
> Select @.Con = DataCon from FileNameCreate
> Select @.A = SerialNo from FileNameCreate
> Select @.B = 'Select * from FileNameCreate + +'
> Select @.str='bcp' + @.B + 'queryout c:\Lut' + @.A + '.txt -
> c -Usa -P -SUKLUN005\UKLUS0004H'
> EXEC master..XP_cmdshell @.str
You need to leave additional spaces in your command string, and you also
need double quotes around a query used with BCP:
select @.str = 'bcp "' + @.B + '" queryout...'
If you're building dynamic strings to execute, it usually helps to 'SELECT
@.str' just before you execute it, at least during development, to make sure
that the command is being built as you expect.
Simon|||Hi Simon
I have edited the file like this: and get error: SQLState
= 37000, NativeError = 170
Error = [Microsoft][ODBC SQL Server Driver]
[SQL Server]Line 1: Incorrect syntax near 'Test2'.
Test2 is correct information from the table....
DECLARE @.A char(100)
DECLARE @.str varchar(200)
DECLARE @.B Char(100)
Select @.B = Datacon from FileNameCreate
Select @.A = SerialNo from FileNameCreate
Select @.str = 'bcp "'+ @.B +'" queryout "c:\Lut.txt" -c -
Usa -P -"SUKLUN005\UKLUS004H"'
EXEC master..XP_cmdshell @.str|||Brian,
> I have edited the file like this: and get error: SQLState
> = 37000, NativeError = 170
> Error = [Microsoft][ODBC SQL Server Driver]
> [SQL Server]Line 1: Incorrect syntax near 'Test2'.
> Test2 is correct information from the table....
> DECLARE @.A char(100)
> DECLARE @.str varchar(200)
> DECLARE @.B Char(100)
You have declare @.A and @.B as fixed character data type. Change them
to varchar(100).
Then substitute the following for the exec statement:
print @.str
--EXEC master..XP_cmdshell @.st
It will then be obvious what your problems are.
Linda|||Brian;
I'd suggest that you put a print statement after you have constructed the
dynamic SQL and comment out the EXECUTE. Run the script to see what SQL
statement you are getting. When you are satisfied with the SQL statement,
comment out the print statement and uncomment the EXECUTE statement. Often,
this is much quicker to a solution than getting feedback from others.
--
Linchi Shea
linchi_shea@.NOSPAMml.com
"Brian" <anonymous@.discussions.microsoft.com> wrote in message
news:003f01c3a610$76060760$a101280a@.phx.gbl...
> Hi Simon
> I have edited the file like this: and get error: SQLState
> = 37000, NativeError = 170
> Error = [Microsoft][ODBC SQL Server Driver]
> [SQL Server]Line 1: Incorrect syntax near 'Test2'.
> Test2 is correct information from the table....
> DECLARE @.A char(100)
> DECLARE @.str varchar(200)
> DECLARE @.B Char(100)
> Select @.B = Datacon from FileNameCreate
> Select @.A = SerialNo from FileNameCreate
> Select @.str = 'bcp "'+ @.B +'" queryout "c:\Lut.txt" -c -
> Usa -P -"SUKLUN005\UKLUS004H"'
> EXEC master..XP_cmdshell @.str
>|||The Print does help. However i now get the following error
Line 7: Incorrect syntax near 'C:\Lut.txt'.
I have tryed the following:
The file exists.
Using ', " and both.|||This is now corrected by 'queryout C:\Lut.txt'
-S Server name
Now i get: Line 7: Incorrect syntax near 'UKLUN005
\UKLUS004H'.
>--Original Message--
>The Print does help. However i now get the following
error
>Line 7: Incorrect syntax near 'C:\Lut.txt'.
>I have tryed the following:
>The file exists.
>Using ', " and both.
>.
>|||Thanks all
BCP is now working and i am now using it in my live
system..............
>--Original Message--
>This is now corrected by 'queryout C:\Lut.txt'
>-S Server name
>Now i get: Line 7: Incorrect syntax near 'UKLUN005
>\UKLUS004H'.
>
>>--Original Message--
>>The Print does help. However i now get the following
>error
>>Line 7: Incorrect syntax near 'C:\Lut.txt'.
>>I have tryed the following:
>>The file exists.
>>Using ', " and both.
>>.
>.
>