Solved

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

Posted on 2014-07-18
7
804 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
[X]
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
  • 3
7 Comments
 
LVL 63

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 63

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
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
LVL 2

Author Comment

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

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

752 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