Collation conflict error of UpdateAsync operation using templates after update from 3.1.6 to 3.2.3
See original GitHub issueAfter updating from linqdb version 3.1.6
to 3.2.3
we have faced with a lot of exceptions when on UpdateAsync operation.
Error:
System.Data.SqlClient.SqlException (0x80131904): Cannot resolve the collation conflict between "SQL_Latin1_General_CP1251_CI_AS" and "Cyrillic_General_CI_AS" in the equal to operation
Example update operation:
var updateTempTable = await db.CreateTempTableAsync(
$"temp_{Guid.NewGuid()}_{nameof(Item)}",
itemsToUpdate, cancellationToken: ct);
var recordsToUpdate =
from s in db.Items.With("NOLOCK")
from t in updateTempTable.InnerJoin(x =>
x.ItemId== s.ItemId)
select new {s, t};
await recordsToUpdate
.Set(v => v.s.Name, v => v.t.Name)
.Set(v => v.s.DateUpdated, v => DateTimeOffset.Now)
.UpdateAsync(ct);
Example table definition:
[Table(Schema="dbo", Name="Item")]
public partial class Item
{
[PrimaryKey, NotNull] public int ItemId { get; set; }
[Column, NotNull] public string Name { get; set; }
[Column, NotNull] public DateTimeOffset DateUpdated { get; set; }
}
Database collation SQL_Latin1_General_CP1251_CI_AS
When we downgrade from 3.2.3
to 3.1.6
, then all works as before.
What was changed? And how to adapt to a new logic?
For all tables, which use as source for creating temp tables we should add creation format of columns? Like:
[Column(CreateFormat = "{0} {1} SQL_Latin1_General_CP1251_CI_AS {2} {3}"), Nullable]
.NET Core 3.1 linq2db version: 3.2.3 Database Server: MSSQL
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to fix a collation conflict in a SQL Server query?
I am working on a view, wherein I am using an inner join on two tables which are from two different servers. We...
Read more >"Cannot resolve the collation conflict" error when you apply ...
Fixes an issue that triggers a "Cannot resolve the collation conflict" error when you apply a snapshot to the subscriber database in SQL...
Read more >cannot resolve collation conflict UTF-8 and Ascii
Cannot resolve the collation conflict between "Latin1_General_100_CI_AI_SC_UTF8" and "Latin1_General_CI_AS" in the equal to operation.
Read more >Untitled
Canna-3.7p1-pod-fix-wrongparam.patch: applied to fix the wrong function parameter. (#113662) - New upstream release. - New upstream release.
Read more >Cannot resolve the collation conflict
Here is my query and I get collation error. SELECT fc.importid, fc.name. FROM dbo.computerdata fc. LEFT JOIN dbo.linuxdata sd ON fc.importid=sd.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Another solution will be adding collation to each column in temp table mapping, so it will use explicit collation instead of tempdb collation.
I see where the problem. In 3.2 we introduced support for real temporary tables, so CreateTemp table default behavior changed to create temporary table, which is created in
tempdb
. In your case tempdb collation differ from collation of your db, which results in collation conflicts.You should update CreateTempTable call to use real table (pre-3.2 behavior)