Not sure why this is failing...I'm sure it's my fault. Any help would be greatly appreciated.
I'm getting the classic
Cannot open database "Northwind" requested by the login. The login failed. Login failed for user 'MyMachine\MyUserName'.
I can login just fine using windows authentication through SQL Server Management Studio.
I checked in SQL Server Management Studio to make sure that my user has permission to use the Northwind database. I also tried most of the other responses to this question posted here on stackoverflow.
This is my code:
SqlConnection dataConnection = new SqlConnection();
try
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = ".\\SQLExpress";
builder.InitialCatalog = "Northwind";
builder.IntegratedSecurity = true;
dataConnection.ConnectionString = builder.ConnectionString;
dataConnection.Open();
... .
I'm using SQL Server 2008 Express
Try doing it this way, it's always worked for me, simpler too as you can create a new SQL connection object directly from a connection string by just specifying the string as a parameter, like this:
string connectionString = @"Server=server\instance;Database=Northwind;Integrated Security=True";
SqlConnection dataConnection = new SqlConnection(connectionString);
try
{
dataConnection.Open();
}
catch (sqlexception e)
{
Messagebox.Show("Error");
}