Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cant execute a bcp in sql 2012

Posted on 2016-10-27
3
Medium Priority
?
77 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 14

Accepted Solution

by:
Nakul Vachhrajani earned 2000 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 70

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

715 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