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?
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.