Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 BCP - Cannot open database requested by the login.

Author  Topic 

jannable
Starting Member

25 Posts

Posted - 2008-10-03 : 01:35:39
Hey folks, I'm dealing with an extremely annoying problem. I've searched for help with this extensively and tried a bunch of steps that others were recommending but without success. Here's the problem: When I use BCP to import data into a table, I get a login failed error. The exact same code runs fine in our dev and test environment - but not in production. I've even gone so far as uninstalling SQL Server and reinstalling. The only difference that I am aware of of is that the production server's install needed SQL Server SP2 installed separately.

Anyway, for more info... my database name is "MyTest" and the table name is "Test". It's schema is as follows:

CREATE TABLE [dbo].[Test](
[F00001] [varchar](8000) NULL,
[F00002] [varchar](8000) NULL
) ON [PRIMARY]

I then make 2 files on the C drive like so...

---- C:\ifile.txt ----
Abc 01
Bcd 12
Cde 23

---- C:\ffile.fmt ----
9.0
2
1 SQLCHAR 0 8000 "\t" 1 F00001 SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 8000 "\r\n" 2 F00002 SQL_Latin1_General_CP1_CI_AS


Now, I run the following command:

DECLARE @cmd varchar(8000)
SET @cmd = 'bcp [MyTest]..[Test] in "C:\ifile.txt" -f "C:\ffile.fmt" -T'
PRINT @cmd
EXEC xp_cmdshell @cmd


And the dreaded response that I get back is as follows:

SQLState = 37000, NativeError = 4060
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database "[MyTest]" requested by the login. The login failed.


There's really nothing much else to share with you. All I know is that there must be some configuration somewhere that is screwing this up.

I've exhausted myself and am now forced to sleep after beating my head over this all day. Please, if anyone can help I would very much be grateful. I'm willing to go through as many mundane steps as necessary to resolve this.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 01:48:31
can you try connecting to your server from sql management studio and see if MyTest db is accesible?
Go to Top of Page

jannable
Starting Member

25 Posts

Posted - 2008-10-03 : 15:13:49
It's absolutely accessible. Btw, I'm even able to use BCP with queryout and I get results. I'm able to access this database in every possible way aside from this one critical method.
Go to Top of Page

jannable
Starting Member

25 Posts

Posted - 2008-10-03 : 15:15:46
I should also add that this works on 4 different servers already. This 5th one is the only one causing an issue and I'm sure it's just some obscure configuration somewhere.
Go to Top of Page

jj30
Starting Member

1 Post

Posted - 2008-10-28 : 16:39:48
I am having the same problem on SQL Express 2008. Can you email me?
Go to Top of Page

Mike Casey
Starting Member

2 Posts

Posted - 2010-07-02 : 06:13:18
Came across this problem recently... on a server that had been upgraded from SQL2000.
The SQL2000 tools path was in the environment path before the SQL2005 tools, and running bcp without specifiying a path to the executable ran the SQL2000 bcp, which has problems with [] around DB names, and with not specifying a DB name.
You can confirm this by running bcp -v and seeing whether an 8.* (MSSQL2000) or a 9.* version is returned.
Specifiying the full path to the SQL2005 tools, getting rid of the SQL2000 tools, or changing order in path gets rid of the problem.
Go to Top of Page

Mike Casey
Starting Member

2 Posts

Posted - 2010-07-02 : 06:58:05
Alternatively, can quote the DBname with "" and use the bcp -q option, as this works with SQL2000 or SQL2005, e.g.
bcp "MyTest"."dbo"."Test" in "C:\ifile.txt" -f "C:\ffile.fmt" -q -T
Go to Top of Page
   

- Advertisement -