I'm also waiting for support to Microsoft.Data.SqlClient.
There's another question about the same issue here: https://learn.microsoft.com/en-us/answers/questions/378770/elastic-scale-client-library-support-and-package-u.html
doesn't look too promising.
Does ShardMap support Microsoft.Data.SqlClient package ?
I have an .net core 6.0 entityframework application and want to connect to SQL Database through Azure Active Directory from the application. The code to connect to SQL Database through Azure Active Directory uses Microsoft.Data.SqlClient as the package. We also have usage of ShardMap in the same DbContext where we are connecting to the database. The ShardMap does not support Microsoft.Data.SqlClient and needs System.Data.SqlClient as the package. Does, ShardMap support Microsoft.Data.SqlClient package ?
Below is piece of code from the DbContext where I am getting the error:
SqlConnection conn = null; //uses Microsoft.Data.SqlClient as the package
try{
var shardMap = GetShardMapManager(Constants.Settings.ShardMapName, configuration);
var connStringBuilder = new SqlConnectionStringBuilder
{
UserID = userId,
Password = password,
ApplicationName = "ABC"
};
conn = shardMap.OpenConnectionForKey(shardingKey, connStringBuilder.ConnectionString, ConnectionOptions.Validate);\
//Gives error at the above line: "Cannot convert source type 'System.Data.SqlClient.SqlConnection' to target type 'Microsoft.Data.SqlClient.SqlConnection'"
/* If the above SqlConnection uses System.Data.SqlClient.SqlConnection as the package, the error does not come up. But, in that case, we cannot use Authentication in the GetDatabaseConnection method.
*/
}
catch (Exception e)
{
......
}
private static ShardMap GetShardMapManager(string shardMapName, IConfiguration configuration)
{
var dbConnectionString = GetDatabaseConnectionString(configuration);
var shardMapManager = ShardMapManagerFactory.GetSqlShardMapManager(dbConnectionString, ShardMapManagerLoadPolicy.Lazy);
var shardMap = shardMapManager.GetListShardMap<int>(shardMapName);
return shardMap;
}
//The method below needs Microsoft.Data.SqlClient to use Authentication=Active Directory Service Principal;
public static string GetDatabaseConnection(IConfiguration config)
{
return
$"Server=tcp:{config["SERVERNAME"]},1433; Authentication=Active Directory Service Principal; " +
$"Encrypt=True; Database={config[DATABASENAME]}; User Id = {clientId}; Password = {password} ";
var connection = new SqlConnection(ConnectionString);
connection.Open();
}
I want to use just one package among Microsoft.Data.SqlClient
and System.Data.SqlClient.SqlConnection
. How can it be made that possible?
Entity Framework Core
C#
1 answer
Sort by: Most helpful
-
Sami Määttä 1 Reputation point
2022-12-28T10:30:05.557+00:00