How do I use SqlContext with the Microsoft.Data namespace?

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:

  1. The last line of code in the example, taken from the SqlDataRecord docs, shows a use of SqlContext.Pipe.Send(), which takes an instance of SqlDataRecord as a parameter.
  2. The ‘cheat sheet’ that is linked to earlier states that SqlDataRecord has moved from the Microsoft.SqlServer.Server namespace to Microsoft.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)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật