linq2db icon indicating copy to clipboard operation
linq2db copied to clipboard

SQL Server temp table collation error

Open AR1ES opened this issue 6 months ago • 3 comments

Describe your issue

If the collation of the server and the specific database of the SQL Server differs, then when using temporary tables, the error "Cannot resolve the collation conflict between ..." appears.

The reason is that when creating a temporary table, you can't define collation. Is it possible to add it forcibly somehow?

Or maybe it is possible to add collation by types at once via the same SqlServer/SqlType.cs as follows: nvarchar({0}) COLLATE database_default

Stacktrace:

Microsoft.Data.SqlClient.SqlException Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Cyrillic_General_100_CI_AS" in the equal to operation..
   at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__211_0(Task`1 result)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at LinqToDB.Data.DataConnection.ExecuteReaderAsync(CommandBehavior commandBehavior, CancellationToken cancellationToken)
   at LinqToDB.Data.DataConnection.ExecuteDataReaderAsync(CommandBehavior commandBehavior, CancellationToken cancellationToken)
   at LinqToDB.Data.DataConnection.ExecuteDataReaderAsync(CommandBehavior commandBehavior, CancellationToken cancellationToken)
   at LinqToDB.Data.DataConnection.QueryRunner.ExecuteReaderAsync(CancellationToken cancellationToken)
   at LinqToDB.Linq.QueryRunner.ExecuteQueryAsync[T](Query query, IDataContext dataContext, Mapper`1 mapper, Expression expression, Object[] ps, Object[] preambles, Int32 queryNumber, Func`2 func, TakeSkipDelegate skipAction, TakeSkipDelegate takeAction, CancellationToken cancellationToken)
   at LinqToDB.Linq.QueryRunner.ExecuteQueryAsync[T](Query query, IDataContext dataContext, Mapper`1 mapper, Expression expression, Object[] ps, Object[] preambles, Int32 queryNumber, Func`2 func, TakeSkipDelegate skipAction, TakeSkipDelegate takeAction, CancellationToken cancellationToken)
   at LinqToDB.Linq.ExpressionQuery`1.GetForEachAsync(Action`1 action, CancellationToken cancellationToken)
   at LinqToDB.Linq.ExpressionQuery`1.GetForEachAsync(Action`1 action, CancellationToken cancellationToken)
   at LinqToDB.AsyncExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken token)

I create a temporary table like this: a

wait dbQ.CreateTempTableAsync(ttName, mainQ, tableOptions: temporaryOptions | TableOptions.DropIfExists)

Environment details

Linq To DB version: 5.4.1

Database (with version): SQL Server 2019

ADO.NET Provider (with version): Microsoft.Data.SqlClient 5.2.1

Operating system: windows 10

.NET Version: net 8

AR1ES avatar Aug 08 '24 18:08 AR1ES