7

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.

3
  • 1
    Were u able to resolve this error? Pls let us know. As we are facing the same issue, it would help. Commented Nov 9, 2017 at 12:16
  • No, I never did it resolved. I ended up using SQL Server password authentication instead of AD authentication. Commented Nov 11, 2017 at 16:12
  • I'm using Powershell to connect to Azure SQL and facing the same issue. If I remove the password and UID I get 'WSTrust response does not have recognized SAML assertion' Commented Sep 3, 2021 at 12:06

1 Answer 1

0

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;
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.