4
votes

I'm attempting to connect to Azure SQL Database via Entity Framework with a connection string similar to this:

Data Source=<server>.database.windows.net;Authentication=Active Directory Integrated;Initial Catalog=<database>

The connection attempt is made within the context of a hosted WPF form running inside AutoCAD 2018. The project is built using .NET Framework 4.6 and EF 6.1.3.

I'm encountering the following error:

Unable to load adalsql.dll (Authentication=ActiveDirectoryIntegrated). Error code: 0x2. For more information, see http://go.microsoft.com/fwlink/?LinkID=513072

Unfortunately the help link doesn't lead to page that provides technical details for this issue. I haven't so far discovered anything on the web elucidating the root cause.

I've also tried this connection string:

Server=tcp:<server>.database.windows.net,1433;Initial Catalog=<database>;Persist Security Info=False;User ID=<username>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication="Active Directory Integrated"

It was copied from the Azure portal's ADO.NET (Active Directory integrated authentication) section. However, with this connection string I get the following error Cannot use 'Authentication=Active Directory Integrated' with 'User ID', 'UID', 'Password' or 'PWD' connection string keywords

But it doesn't contain a password segment. And after removing the User ID segment, I still get the Unable to load adalsql.dll ... error.

1
Were u able to resolve this error? Pls let us know. As we are facing the same issue, it would help.Touhid K.
No, I never did it resolved. I ended up using SQL Server password authentication instead of AD authentication.CalvinDale

1 Answers

0
votes

The connection string Server=<server>.database.windows.net,1433; Authentication=Active Directory Integrated; Initial Catalog=<database>; works if you follow this hack:

    /// <summary>
    /// HACK: Refer to https://stackoverflow.com/a/19130718/852956
    /// </summary>
    public void FixEfProviderServicesProblem() {
        //The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer'
        //for the 'System.Data.SqlClient' ADO.NET provider could not be loaded. 
        //Make sure the provider assembly is available to the running application. 
        //See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

        SqlProviderServices instance = SqlProviderServices.Instance;
    }