Skip to content

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

@AugustoDeveloper

Description

@AugustoDeveloper

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    By Design 🎨Issues due to driver feature design and will not be fixed.Waiting for Customer ⏳Issues/PRs waiting for user response/action.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions