Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 1st, 2007, 12:39 PM
Registered User
 
Join Date: Jul 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default BCP out errors, help please.

Hello All,

I keep getting this error when I run BCP.

SQLState = 37000, NativeError = 4060
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database requested in login '[primate_quotes]'. Login fails.

EXEC master..xp_cmdshell
'bcp [DB].dbo.[table].[TXTCOL] out c:\test.txt -c -Uxxx -PXXX -Sservername'

Some of the query variants I have tried:

"[DB].dbo.[table].[TXTCOL]"
DB.dbo.table.TXTCOL
DB.dbo.table
[DB].dbo.[table]
"c:\test.txt"
-U xxx -PXXX -Sservername
-U"xxx" -P"XXX" -S"servername"

and everything inbetween.

I have researched this on Google and tried a lot of the suggestions, but still nothing.

Most of the suggestions I have read point to user pass not being correct for the table access rights.

I know the user and pass I am using have system admin rights, but I went ahead and created a new user with all priv and rights, but again the same results.

Please any suggestions?

 
Old August 1st, 2007, 07:51 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Lookup the BCP utility (overview) in Books Online... there you will find the correct syntax for the command. Your problem is that you are using a column name where the database name goes and that cannot be done...

Code:
The red highlighted item in you code is wrong...
EXEC master..xp_cmdshell
'bcp [DB].dbo.[table].[TXTCOL] out c:\test.txt -c -Uxxx -PXXX -Sservername'
If you don't want to export the whole table, you will need to provide a query to the BCP command. The query can be an EXEC of an existing stored procedure.

--Jeff Moden
 
Old August 3rd, 2007, 03:13 PM
Registered User
 
Join Date: Jul 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Jeff,

Thank you for the advice.

I went back and reviewed the BOL ref and omitted the .[TEXTCOL] and got the same results. I found the .[TEXTCOL] from a google result. Somtimes google is my friend, sometimes not so much.

I tried 3 examples from BOL total before I came up with this variant that ended up working for me...

EXEC master..xp_cmdshell
'bcp "SELECT * FROM datbase_name.dbo.[table_name]" queryout "c:\test.txt" -c -S"servername" -U"xxx" -P"XXX"'

The two things I did different from BOL is removed the [] brackets from dbo and changed the out statement to be queryout as highlighted in red.

Thank you again.

 
Old August 3rd, 2007, 04:33 PM
Registered User
 
Join Date: Jul 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok to make everything easier I put it into an SP, here it is...

DECLARE @FileName varchar(50),
        @bcpCommand varchar(2000)

        SET @FileName = 'c:\_dir\'+'_filename'+CONVERT(char(6),GETDATE(),1 2)+'.txt'
        SET @bcpCommand = 'bcp "SELECT * FROM primate_quotes.dbo.[CC_CSV]" queryout "'
        SET @bcpCommand = @bcpCommand + @FileName + '" -c -S"SNAME" -U"xxxx" -P"XXXX"'

EXEC master..xp_cmdshell @bcpCommand

 
Old August 3rd, 2007, 09:14 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

NOW you're cooking! Thanks for the feedback!

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
bcp error SpringSummer SQL Server 2005 1 July 12th, 2007 02:18 AM
bcp Danielk SQL Server 2000 3 June 12th, 2006 11:14 AM
Can't get errors to display with <html:errors> michaeldill JSP Basics 0 August 2nd, 2004 01:47 PM
BCP API chiefg SQL Server 2000 0 May 14th, 2004 02:22 PM
Bcp utility jejyjose SQL Server 2000 1 October 16th, 2003 08:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.