Solved

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

Posted on 2009-07-10
8
1,713 Views
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.
0
Comment
Question by:APHComputersLtd
  • 4
  • 4
8 Comments
 
LVL 41

Expert Comment

by:pcelba
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.
0
 

Author Comment

by:APHComputersLtd
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.
expert.bmp
0
 
LVL 41

Assisted Solution

by:pcelba
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.
0
 

Author Comment

by:APHComputersLtd
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

expert2.bmp
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:APHComputersLtd
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.
0
 
LVL 41

Assisted Solution

by:pcelba
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.
0
 

Accepted Solution

by:
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
0
 
LVL 41

Expert Comment

by:pcelba
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!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now