I’m looking at migrating a .Net Framework application from System.Data.SqlClient to Microsoft.Data.SqlClient.
The application targets .Net Framework 4.7.2.
I’ve followed the guidance for Microsoft.Data.SqlClient v5 found in the porting cheatsheet linked from the Introduction to Microsoft.Data.SqlClient namespace.
If we look at the documentation for SqlDataRecord, being careful to ensure we’re looking at the documentation for the correct namespace and for .Net Framework, we find the following code example:
//using Microsoft.Data.SqlClient.Server;
[Microsoft.Data.SqlClient.Server.SqlProcedure]
public static void CreateNewRecord()
{
// Variables.
SqlDataRecord record;
// Create a new record with the column metadata. The constructor is
// able to accept a variable number of parameters.
record = new SqlDataRecord(new SqlMetaData[] { new SqlMetaData("Column1", SqlDbType.NVarChar, 12),
new SqlMetaData("Column2", SqlDbType.Int),
new SqlMetaData("Column3", SqlDbType.DateTime) });
// Set the record fields.
record.SetString(0, "Hello World!");
record.SetInt32(1, 42);
record.SetDateTime(2, DateTime.Now);
// Send the record to the calling program.
SqlContext.Pipe.Send(record);
}
Two things to highlight here:
- The last line of code in the example, taken from the
SqlDataRecord
docs, shows a use ofSqlContext.Pipe.Send()
, which takes an instance ofSqlDataRecord
as a parameter. - The ‘cheat sheet’ that is linked to earlier states that
SqlDataRecord
has moved from theMicrosoft.SqlServer.Server
namespace toMicrosoft.Data.SqlClient.Server
.
We have several similar usages of SqlContext
in the application that I am migrating but, as far as I can tell, wherever SqlContext.Pipe.Whatever()
expects a parameter of type SqlDataRecord
, it is expecting the type from the pre-migration namespace (Microsoft.SqlServer.Server
) and never Microsoft.Data.SqlClient.Server
, so my migrated code doesn’t compile.
Following the click-trail in the docs…
- We start at Microsoft.Data.SqlClient.Server.SqlDataRecord, which is where the example came from.
- From there we click on ‘SqlContext’, which takes us to Microsoft.SqlServer.Server.SqlContext.
- Next we click through to the type returned from the
SqlContext.Pipe
property, which is Microsoft.SqlServer.Server.SqlPipe - Finally, we can look at the docs for
SqlPipe.Send()
, which are here, where we see it expects the pre-migration namespace.
So, as far as I can tell, the example in the SqlDataRecord
docs would not compile, just as my code does not compile.
What have I missed?
(note: the click-throughs end up on the docs for .Net Framework 4.8.2, but the 4.7.2 docs are the same for the points that I’m highlighting and I didn’t want to fudge the click-through)