Solved

Cant execute a bcp in sql 2012

Posted on 2016-10-27
3
69 Views
Last Modified: 2016-10-27
My line of code is

Exec xp_cmdshell 'bcp "Select Customer, Invoice from CompanyA.dbo.ArInvoice" queryout "C:\bcptest.txt -S HPELITE\MSSQLSERVER12 " -T -c -t,'

this does not work...

SQLState = S0002, NativeError-208
Error=[Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid object name 'CompanyA.dbo.ArInvoice'.
SQLState=37000. Native Error = 8180
Error=[Microsoft][SQL Server Native Client 10.0][SQL Server]Statement(s) could not be prepared
NULL


Exec xp_cmdshell 'bcp "Select * from sysfiles" query out "C:\bcptext.txt" -T -c -t,' works very well.. exports looks perfect
0
Comment
Question by:Mikeyman_01
3 Comments
 
LVL 13

Accepted Solution

by:
Nakul Vachhrajani earned 500 total points
ID: 41862600
Are your quotation marks correct? I see you have a quotation mark that starts after "queryout", but ends after the server instance name.

It should be:

Exec xp_cmdshell 'bcp "Select Customer, Invoice from CompanyA.dbo.ArInvoice" queryout "C:\bcptest.txt" -S HPELITE\MSSQLSERVER12  -T -c -t,'

Also, check if there are any spaces in the DB name or the object name. If yes, use square brackets:

Exec xp_cmdshell 'bcp "Select Customer, Invoice from [CompanyA].[dbo].[ArInvoice]" queryout "C:\bcptest.txt" -S HPELITE\MSSQLSERVER12  -T -c -t,'
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 41862611
Invalid object name 'CompanyA.dbo.ArInvoice'.

1) Is the db name "CompanyA" valid?  
2) Does that table name exist in that db?  
3) Does the user running the bcp have access rights to that table?
0
 

Author Closing Comment

by:Mikeyman_01
ID: 41862649
Perfect.. I had my quotes wrong.. stupid mistake.. thank you
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question