Solved

Hard time connect to SQL database hosted on Visual Studio 2013 project

Posted on 2014-07-18
7
767 Views
Last Modified: 2014-08-04
When debugging and testing the web application that was developed in-house, I get the error:
Cannot open database "dbname" requested by the login. The login failed.
Login failed for user 'domain\user'

The database is set up with Windows Authentication and tries to use my Windows Account to authenticate with.

Opening "SQL Server Object Explorer" I generate a query to add myself under Security-> users of the database.

CREATE USER [domain\user] FOR LOGIN [domain\user];

Open in new window


I then do:
EXEC sp_addrolemember 'db_owner', 'domain\user'

Open in new window


In the end I right click the account that is now showing under Security-> users and choose "view permissions."

I then get:

/*

No permissions were found for [domain\user] or all existing permissions are open in other windows

*/

Can't see the permission elsewhere, but try to run the application in Visual Studio again. I then end up with the same error as in the beginning.

This database is just hosted via the Visual Studio Project that I need for some testing. It is not hosted on a full SQL Server. There is no SQL Server Management Studio installed. I need to work this out using my Visual Studio 2013 preferably.
0
Comment
Question by:itnifl
  • 4
  • 3
7 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40204349
Hi itnifl;

Does your connection string look like the following.

"Data Source=[domain]\[Instance];Initial Catalog=DatabaseName;Integrated Security=True"

Where
[domain]\[Instance] = Something like Server1\SQLEXPRESS
DatabaseName = The database name you want to connect to.
0
 
LVL 2

Author Comment

by:itnifl
ID: 40204358
It looks lke this:
Data Source=(localdb)\Projects;AttachDbFilename=C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\SSDT\<databasename>.mdf;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40204377
In Visual Studio in the Server Explorer window if you right click on the database you are trying to connect to and select Modify Connection and then in the dialog that opens click on the button marked Test Connection does it pass?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 2

Author Comment

by:itnifl
ID: 40204406
Yes, it does pass.
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40204538
Sorry do not know why you are getting, "Login failed for user 'domain\user'", when you have added the user and Windows is sending the user info to the database. I will continue looking for more info and if I find something I will post here.
0
 
LVL 2

Author Comment

by:itnifl
ID: 40205273
Thank you.
0
 
LVL 2

Author Closing Comment

by:itnifl
ID: 40238945
Seems that Initial Catalog was DatabaseName, but when we attached the mdf file in my copy of the project, the database was named c:\<very long path to database>\DatabaseName.mdf and that was why I had problems debugging the system. I changed the name to the real DatabaseName. However, in the properties if the database, it was just named its DatabaseName without any long path name, so I didn't really see the error at first, being blinded by the thought that it was named correct.

Setting the permisions is still a mystery though. I get this message when viewing the permissions on the user object under security->users in the DB:
"No permissions were found for domain\user or all existing permissions are open in other windows"

But that really does not bother me as long as I can connect and debug as I should.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

895 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

15 Experts available now in Live!

Get 1:1 Help Now