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
I'm using a lot of SqlDataRecord for mass insert/update/delete on multiple tables and when reading the documentation about SqlDataRecord i don't see any guideline on how to reuse these SqlDataRecord objects. The only thing mentioned on the docs is:
you should re-use existing SqlDataRecord objects instead of creating new ones every time
I have looked into ObjectPool class to reuse these objects, but in my use case it won't work because ObjectPool when used in DI is singleton and i would need an ObjectPool per "table" (like the HttpClientFactory named client pattern)
You can interpret the documentation as you should reuse a SqlDataRecord for each row. The assumption is you insert multiple rows, so you don't need to recreate the SqlDataRecord for each one. However you implement the object reuse is up to you, and ObjectPool is just one .NET feature.
I'd also like to know the answer to what @0x53A asked, because I use this pattern frequently. The documentation assumes we're using a SqlPipe and returning data from a CLR stored procedure, but the pattern we're asking about is sending data as a TVP.
@lcheunglci Please reopen. I also need to know the answer to what @0x53A asked. While the approach works in practice, it's sketchy (unless officially documented) because it relies on implementation details of how the SqlClient library uses the IEnumerable. There should be clear documentation on whether it is okay to use the pattern that @0x53A posted
Investigating #3957 brought me back to this conversation, so I'm reopening it. Looks like we need some general improvements around SqlDataRecord documentation.
Activity
JRahnama commentedon Oct 17, 2022
@xaviergxf we will look into this soon.
lcheunglci commentedon Oct 18, 2022
You can interpret the documentation as you should reuse a
SqlDataRecordfor eachrow. The assumption is you insert multiple rows, so you don't need to recreate theSqlDataRecordfor each one. However you implement the object reuse is up to you, andObjectPoolis just one .NET feature.lcheunglci commentedon Oct 25, 2022
Closing due to inactivity.
0x53A commentedon Dec 21, 2022
Hi, can you please confirm or deny if the following kind of reuse is safe?
Please see https://stackoverflow.com/questions/37007018/is-it-safe-to-reuse-a-sqldatarecord
This is then passed to SqlClient as a Parameter via Dapper:
(Dapper is just sugar for creating an SqlCommand and filling the SqlParameter)
Dean-NC commentedon Feb 22, 2023
I'd also like to know the answer to what @0x53A asked, because I use this pattern frequently. The documentation assumes we're using a SqlPipe and returning data from a CLR stored procedure, but the pattern we're asking about is sending data as a TVP.
munik commentedon Jun 23, 2025
@lcheunglci Please reopen. I also need to know the answer to what @0x53A asked. While the approach works in practice, it's sketchy (unless officially documented) because it relies on implementation details of how the SqlClient library uses the IEnumerable. There should be clear documentation on whether it is okay to use the pattern that @0x53A posted
mdaigle commentedon Feb 17, 2026
Investigating #3957 brought me back to this conversation, so I'm reopening it. Looks like we need some general improvements around SqlDataRecord documentation.