Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-07-18
7
Medium Priority
?
848 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 64

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 64

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
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!

 
LVL 2

Author Comment

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

Accepted Solution

by:
Fernando Soto earned 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

927 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