question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Collation conflict error of UpdateAsync operation using templates after update from 3.1.6 to 3.2.3

See original GitHub issue

After 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MaceWinducommented, Feb 15, 2021

Another solution will be adding collation to each column in temp table mapping, so it will use explicit collation instead of tempdb collation.

1reaction
MaceWinducommented, Feb 15, 2021

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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found