[Microsoft][ODBC SQL Server Driver][SQL server]Cannot open database requested by the login. the login failed

Posted on 2009-07-10
Last Modified: 2012-05-07
Hi Dear Experts, I am facing the following error: [Microsoft][ODBC SQL Server Driver][SQL server]Cannot open database requested by the login. the login failed when i call the following command in sql2005, bcp [servername].[dbo].[tablename] out c:\T1Export.csv  -w    -t\t -S machinename-U sa -Ppassword.
the command works fine on my machine, but not on the customer site.
my machine is a development machine but on the customer machine i just have sql server ,no MS office and no MDAC. Do i need to install any thing. I very much appriciate any help. thanks.
Question by:APHComputersLtd
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
  • 4
  • 4
LVL 42

Expert Comment

ID: 24825132
It cannot work if the command is really "bcp [servername].[dbo].[tablename] out ..." and the database name is different from sarvername.

It should be:
"bcp [databasename].[dbo].[tablename] out ..."

You may also look if the sa user is enabled.

Author Comment

ID: 24838777
Hi Pcelba,
Thanks for your reply, I noticed that i had typing mistake in my question, it is databasename which i used after bcp.
re the sa user, i can  login using sql authent. by user sa although when you look at the security\users node under the specified database i have users such as dbo,buildin administrators,,,,, but not sa explicityly. but the dbo loginnn. although i have the user sa declared under the selected server, please find attached snapshot. Hope this could give you some ideas about where the problem is.
Many thanks.
LVL 42

Assisted Solution

pcelba earned 150 total points
ID: 24839185
User dbo uses sa login. You have to look at logins for the whole SQL Server. If the sa login has the red arrow near its name (like user guest on your snapshot picture) then it is disabled. Double click the sa login to view/change its properties (like disabled status, password, etc.). The standard setting for sa login is "disabled" due to the security resons.

Also look at User mappings page on sa properties window. sa login should have mapped your database.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 24839617
The sa user doesn't have a red arrow  next to it and it is enabled.
but i just come acoross the following :
When i run BCP master..sysobjects out c:\sysobjects.txt -c -t, -T , it works and creates the file but if i run bcp [HKTest].[dbo].[tbfinalreport] out c:\ScheduleReport.csv  -c -t, -T , it does come up with a login failure. please see attached


Author Comment

ID: 24839659
I forgot to tell you that i am doing RemoteDesktop to the customer site. As you probably noticed the bcp command that doesn;t have any -T switch does ask for a password but no matther whether i type in the windows administrator password or sql password it doesn't like it. I am sure it is something to do with the login set up on this server, please help . Thanks.
LVL 42

Assisted Solution

pcelba earned 150 total points
ID: 24846996
If the user who has trusted login (-T parameter) allowed can access master database then it must be possible to allow him other database usage.

You have to do it on Server level: Security - Logins. Double click on the login which is logged on the remote computer and on the "User mappings" page map the hktest database to him.

Accepted Solution

APHComputersLtd earned 0 total points
ID: 24847433
I figured it out but i am not sure why its acting like this, in the command below if we remove the pair of brackets around the database name and leave the rest it works.
so it should be  bcp HKTest.[dbo].[tbfinalreport] out c:\ScheduleReport.csv  -c -t, -T  
instead of  bcp [HKTest].[dbo].[tbfinalreport] out c:\ScheduleReport.csv  -c -t, -T
LVL 42

Expert Comment

ID: 24847950
Interesting. Above syntax should be equivalent for SQL Server. But it is not true for bcp utility... I am learning instead of helping.

So, please assign your last comment as the accepted answer to preserve it for future references.

And thanks!

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL Server Management Studio R2 4 60
Dump data from mysql to xls php 10 55
How to capture server information using powershell 3 59
relocating SQL 2000 18 30
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 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