Solved

Cant execute a bcp in sql 2012

Posted on 2016-10-27
3
71 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

739 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