Windows Logins are not supported in this version of SQL Server

Connecting to SQL Azure...

If you're attempting to connect to some on-premises SQL server, you can do something like the following:

Code Snippet
1
2
3
4
5
var connectionString = @"Server=XXXXXXXXXX.yyyy.dom;Database=MyDatabaseName;Integrated Security=true;";
using (var connection = new SqlConnection(connectionString))
{
	connection.Open();
}

But if you're connecting to SQL Azure, this won't cut it. If you do try the analogous code, you'll get the following error:

Instead you'll need something along the lines of the following:

Code Snippet
1
2
3
4
5
6
7
8
9
10
11
12
13
var connectionString = new SqlConnectionStringBuilder();
connectionString.DataSource = "MyCrazyKey.database.windows.net";
connectionString.InitialCatalog = "MyDatabaseName";
connectionString.Encrypt = true;
connectionString.TrustServerCertificate = false;
connectionString.UserID = "myAzureUserName@MyCrazyKey";
connectionString.Password = "MyCrazyPassword";
return connectionString;

using (var connection = new SqlConnection(connectionString.ToString()))
{
	connection.Open();
}

See also this Microsoft article for further help.

Fixed.

portrait title

About Scott

I am a software engineer from Bozeman, MT enjoying the slightly warmer climate of Colorado. I think code can change lives. I think lives are worth changing. I write code.

You can find me on Twitter, LinkedIn, , and Github.