How to force Microsoft.EnterpriseLibrary.Data SqlDatabase to use the Microsoft.Data.SqlClient package

Evaristo Laron 0 Reputation points
2025-01-15T20:54:33.57+00:00

I am trying to access an azure database using a connection string provided that uses the Authentication keyword. The SqlDatabase in EnterpriseLibrary.Data uses the System.Data.SqlClient that does not work with my connection string. Is it possible to force the sqlclient to use the Microsoft.Data.SqlClient or look into another framework?

Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 27,596 Reputation points
    2025-01-15T22:20:26.3366667+00:00

    Since SqlDatabase in Microsoft.EnterpriseLibrary.Data internally uses System.Data.SqlClient, you cannot directly replace it without modifying the library. However, you can work around this by replacing SqlDatabase with custom code that explicitly uses Microsoft.Data.SqlClient.

    Or you can create a custom database class to use Microsoft.Data.SqlClient for connecting to the Azure database.
    Then check if your connection string includes the necessary keywords for Azure SQL Database authentication, such as Authentication=Active Directory Password; if using Azure AD, or other required authentication modes.

    If you're using Microsoft.EnterpriseLibrary.Data primarily for database access, migrate the relevant parts of your code to use the CustomSqlDatabase class.

    As a recommendation if you are open to using other frameworks, consider switching to:

    • Entity Framework Core: A modern ORM that supports Microsoft.Data.SqlClient natively.
    • Dapper: A lightweight ORM with excellent performance and support for Microsoft.Data.SqlClient.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.