Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a System.Data.SQLClient.SQLConnection with Active Directory Universal Authentication

I was using the below code to connect to SQL Azure DB that was using Active Directory Integrated Authentication.

private string GenerateConnectionString(string databaseName, string serverName)
{
    SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder();
    sqlConnectionBuilder.DataSource = string.Format(
        "tcp:{0}.database.windows.net",
        serverName);
    connBuilder.InitialCatalog = databaseName;
    connBuilder.Authentication = SqlAuthenticationMethod.ActiveDirectoryIntegrated;
    connBuilder.ConnectTimeout = 30;
    return connBuilder.ConnectionString;
}

The authentication is changed from Active Directory Integrated Authentication to Active Directory Universal Authentication to support multi-factor authentication.

I see the enumeration System.Data.SqlClient.SqlAuthenticationMethod doesn't have a value for Active Directory Universal Authentication. Is it possible to still use the System.Data.SqlClient to connect to the DB? If yes, what is the change I have to do in the code?

enter image description here

like image 458
shanmuga raja Avatar asked Feb 06 '17 20:02

shanmuga raja


People also ask

What is System data SqlClient SqlConnection?

A SqlConnection object represents a unique session to a SQL Server data source. With a client/server database system, it is equivalent to a network connection to the server. SqlConnection is used together with SqlDataAdapter and SqlCommand to increase performance when connecting to a Microsoft SQL Server database.


1 Answers

ActiveDirectoryInteractive authentication method is available since the .NET Framework 4.7.2. Not sure if it is the same as "Universal" or not.

like image 66
Andrey Belykh Avatar answered Oct 06 '22 08:10

Andrey Belykh