Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Define a custom buffer size to streaming data to SQL Server #3788

Unanswered
AugustoDeveloper asked this question in Q&A
Discussion options

Hey, i have a question: Is there a way to define a custom buffer size to streaming data to SQL Server?

The code below uses a Stream to insert a large file into column called Data. The file size is 800MB .

const string Statement =
"""
INSERT INTO [dbo].[Stream]
 (Id, Data)
VALUES
 (@Id, @Data);
""";
using var input = File.OpenRead("/tmp/dfs/data/1/sample.txt");
using var connection = new SqlConnection(ConnectionString);
connection.Open();
using var cmd = new SqlCommand(Statement, connection);
cmd.Parameters.AddWithValue("@Data", input);
cmd.Parameters.AddWithValue("@Id", 1);
cmd.ExecuteNonQuery();

I noticed when i run, the chunk size used to streaming is 4096 and cannot find a way to set a different size. Debugging the code i found the line where is create the buffer with a constant size:

https://github.com/dotnet/SqlClient/blob/fc514f6b8ffe0e0b664daaf5dad4f7f883a8a975/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParser.cs#L12872C12-L12880C55

Can you help me ?

Thanks

You must be logged in to vote

Replies: 4 comments

Comment options

@AugustoDeveloper There is no API that allows configuring this buffer size. You can refer to the streaming support documentation here.

You must be logged in to vote
0 replies
Comment options

Yeah, i already readed this doc... no much helpful for this case. Is there any chance in future to create some api for this?

@AugustoDeveloper There is no API that allows configuring this buffer size. You can refer to the streaming support documentation here.

You must be logged in to vote
0 replies
Comment options

Have you benchmarked it and seen that the buffer size is a bottleneck? If so can you share the bench setup?
I've have thought that the limit would be the network for this since it'll be sending to the server over the network. Unless the packet size is slightly larger than the buffer it'd complicate the packetization slightly but not enough to cause a performance problem.

You must be logged in to vote
0 replies
Comment options

Ok, I'll benchmark and bring the results.

Have you benchmarked it and seen that the buffer size is a bottleneck? If so can you share the bench setup?
I've have thought that the limit would be the network for this since it'll be sending to the server over the network. Unless the packet size is slightly larger than the buffer it'd complicate the packetization slightly but not enough to cause a performance problem.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #3734 on November 20, 2025 20:39.

AltStyle によって変換されたページ (->オリジナル) /