Reputation: 5395
I created a C# console application, and need to access my database.
var connectionString = "Data Source=MyServer;Integrated Security=True;Initial Catalog=MyDB;";
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
}
The .Open()
gives an exception:
"Cannot open database "MyDB" requested by the login. The login failed."
Could you please help me with this? Should I give some permission to my application? How can I do it on Windows 7?
Upvotes: 1
Views: 5129
Reputation: 48134
If you're using Windows auth you shouldn't need a user name and password (your login to Windows is sufficient, assuming it has permissions on the database). Otherwise you'll need a username and password for the db.
Also, I'm not sure it matters, but always a good idea to run your application as admin when you have permissions issues.
Upvotes: 1
Reputation: 8295
You should try specifying the user and the password in the connection string.
var connectionString = "Data Source=MyServer;Integrated Security=True;Initial Catalog=MyDB;user=you;password=password;";
Upvotes: 3