SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


bcp error through xp_cmdshell


bcp error through xp_cmdshell

Author
Message
Ambuj Mathur
Ambuj Mathur
SSC Journeyman
SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)

Group: General Forum Members
Points: 88 Visits: 282
I need to extract a table data in SQL server into a file and store it at a place on Windows drive.
But when I run the below command,

master..xp_cmdshell 'bcp .. out -U -P '

I get the following error message:

CTLIB Message: - L6/O8/S5/N3/5/0:
ct_connect(): directory service layer: internal directory control layer error: Requested server name not found.
Establishing connection failed.

Can anyone help in understanding this and provide a solution?
Thanks! Smile
Lowell
Lowell
One Orange Chip
One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)

Group: General Forum Members
Points: 29537 Visits: 39986
master..xp_cmdshell 'bcp ..out -U -P '


i guess you need to read up on the syntax. If that is your real command, you are not specifying any of the required values;
here's a working example:

declare @sql varchar(4000),
@rowcount int
--sample query: you would do the same to your existing bcp
set @sql = 'bcp "SELECT TOP 5 * FROM SYSOBJECTS" queryout "c:\body.txt" -c -U"sa" -P"NotARealPassword"'
--export via bcp
insert into #results
EXEC master..xp_cmdshell @sql



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Ambuj Mathur
Ambuj Mathur
SSC Journeyman
SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)

Group: General Forum Members
Points: 88 Visits: 282
Thanks Lowell!
I did try the code sent by you but I'm still getting the same error message as before -

CTLIB Message: - L6/O8/S5/N3/5/0:
ct_connect(): directory service layer: internal directory control layer error: Requested server name not found.
Establishing connection failed.


Can you interpret the message and advice? Wink
dragana kubura
dragana kubura
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 Visits: 45
If you have a sybase client installed on that server, check your path variable. This sounds to me like sybase error. If you need more information, please let me know.
JasonYousef
JasonYousef
SSC-Enthusiastic
SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)SSC-Enthusiastic (179 reputation)

Group: General Forum Members
Points: 179 Visits: 676
Hi,
I'm having the same problem and Ive sybase client installed, so what path variables you're talking about here and how to change it?

Thanks
Lowell
Lowell
One Orange Chip
One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)

Group: General Forum Members
Points: 29537 Visits: 39986
huslayer (6/1/2011)
Hi,
I'm having the same problem and Ive sybase client installed, so what path variables you're talking about here and how to change it?

Thanks

the %PATH% allows you to do things like just type "notepad.exe" in the run command and let the operating system resolve the actual path to the executable for you behind the scenes....
but if you have the same executable in two or more folders that exist in the path, you are not guaranteed to call the one you were thinking about...it's just the first one the OS finds.

if you go to a command window and type echo %PATH%

you might see a path to a sybase folder as well as to SQL server..so which bcp is it going to decide to use?

So to fix that you might need to explicitly put the entire path to the SQL server bcp, ie like this:


declare @sql varchar(4000),
@rowcount int
--sample query: you would do the same to your existing bcp

--due to %path% issues, identify the full path to bcp
set @sql = 'C:\Program Files (x86)\Microsoft SQL Server\90\Tools\Binn\bcp.exe "SELECT TOP 5 * FROM SYSOBJECTS" queryout "c:\body.txt" -c -U"sa" -P"NotARealPassword"'
--export via bcp
insert into #results
EXEC master..xp_cmdshell @sql






Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search