dotnet / dotnet/SqlClient

Bug in SQL Server provider when using UTF8 collations

Open
#2,035 14 comments 1 reaction 0 assignees View on GitHub
Repro Available :heavy_check_mark:
Dominant language
C#
Stars
989
Forks
340
Avg merge
4d 19h
Merged PRs (30d)
72

Description

I've encountered exceptions when using EF with SQL Server and configuring

* the database and all column collations to be a UTF8 collation and
* all columns to use `varchar` rather than `nvarchar` (as one should with UTF8 collations on SQL Server, somewhat counter-intuitively).

I've been doing this for a while now without obvious issues, but in a project that does some massive import of larger text portions some of the inserts fail with an exception:

```
SqlException: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 7 ("@p8"): Data type 0xA7 has an invalid data length or metadata length.
```

This does not happen with the traditional `nvarchar` type, and it happens only in some (thankfully reproducible) circumstances.

I have [reduced my import to a test case](https://github.com/jtheisen/creational/tree/testcase-for-utf8-issue). See instructions to reproduce there.

### Version information

SQL Server version: Microsoft SQL Server Developer (64-bit) 16.0.1050.5 on Windows
EF Core version: 6.0.16
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.5.2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.