Solved

Cant execute a bcp in sql 2012

Posted on 2016-10-27
3
58 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 12

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql help 8 55
MS SQL Merging data from table into another table 1 32
SQL Help 27 40
Why i am getting a star, SSMS does not show me any error. Division Error 5 20
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

806 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