Solved

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

Posted on 2014-07-18
7
759 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Author Comment

by:itnifl
Comment Utility
Yes, it does pass.
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
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
Comment Utility
Thank you.
0
 
LVL 2

Author Closing Comment

by:itnifl
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

763 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

6 Experts available now in Live!

Get 1:1 Help Now