Solved

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

Posted on 2014-07-18
7
790 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
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…

756 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