You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you are using a SQL server connection with Always Encrypted with secure enclaves, if you try to use SqlDataAdapter.Fill to fill a DataSet, using an SqlCommand which is a stored procedure without parameters it goes in error with NullReferenceException on BuildStoredProcedureStatementForColumnEncryption
To reproduce
Tested with "Microsoft.Data.SqlClient" Version "2.1.3" and "Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" Version "2.0.0"
private static void SqlError()
{
using (var dbConnection = new SqlConnection("Data Source=[server];Initial Catalog=[db];Column Encryption Setting=Enabled;Attestation Protocol=AAS;Enclave Attestation Url=[secureEnclaveUrl];User ID=[user];Password=[pwd]"))
{
dbConnection.Open();
DataSet ds = new DataSet("Results");
IDbCommand dbCommand = dbConnection.CreateCommand();
dbCommand.CommandText = "[YourStoredProcedure]";
dbCommand.CommandType = CommandType.StoredProcedure;
if(dbCommand.Parameters != null)
{
//This is a workarond which triggers the parameters lazy creation
//https://github.com/dotnet/SqlClient/blob/3df7de613aecee3a8b5229333c84142e6e83ae9d/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs#L889
}
using (var da = new SqlDataAdapter(dbCommand as SqlCommand))
{
//This works
da.Fill(ds);
}
dbCommand = dbConnection.CreateCommand();
dbCommand.CommandText = "[YourStoredProcedure]";
dbCommand.CommandType = CommandType.StoredProcedure;
using (var da = new SqlDataAdapter(dbCommand as SqlCommand))
{
//NullReferenceException on BuildStoredProcedureStatementForColumnEncryption
//https://github.com/dotnet/SqlClient/blob/3df7de613aecee3a8b5229333c84142e6e83ae9d/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs#L5839
da.Fill(ds);
}
}
}
Expected behavior
It shouldn't be necessary to force lazy creation of Parameters when the command has no parameters
The text was updated successfully, but these errors were encountered:
Description
If you are using a SQL server connection with Always Encrypted with secure enclaves, if you try to use SqlDataAdapter.Fill to fill a DataSet, using an SqlCommand which is a stored procedure without parameters it goes in error with NullReferenceException on BuildStoredProcedureStatementForColumnEncryption
To reproduce
Tested with "Microsoft.Data.SqlClient" Version "2.1.3" and "Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" Version "2.0.0"
Expected behavior
It shouldn't be necessary to force lazy creation of Parameters when the command has no parameters
The text was updated successfully, but these errors were encountered: