Developer forum

Forum » Feature requests » Handling for Contained databases and collations

Handling for Contained databases and collations

Scott Forsyth Dynamicweb Employee
Scott Forsyth
Reply

Hello,

With hosting in Azure databases, we run into Containment and Collation issues from time to time. I just ran into an issue again where I couldn't edit any of the integration Endpoints from the backend.  When trying to make a change, it throw this error: Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_100_CI_AS_KS_WS_SC" in the equal to operation.

The database and all tables and columns are all using SQL_Latin1_General_CP1_CI_AS. I was able to narrow down and get a query to repro it. This is a subset of the query used to update Endpoint.

MERGE [Endpoint] WITH (SERIALIZABLE) AS T USING (VALUES  (0, 1, 0) ) AS S
(SourceIndex, EndpointId, EndpointUseInLiveIntegration)    ON T.EndpointId = S.EndpointId
WHEN MATCHED THEN UPDATE SET EndpointUseInLiveIntegration = 0 
OUTPUT CASE WHEN $action = 'INSERT' THEN 'something' ELSE 'something else' END AS TestVal;

It's the $action that is the problem. That uses a different collation than the database and columns, causing the collation clash. Here's a good forum that discusses it: https://www.sqlservercentral.com/forums/topic/contained-database-or-not

For now, I'll work around it by turning off containment on this particular database (it's a copy from Azure, on a local SQL server). But, it would be nice to have the platform handle for this situation.

The solution is to add this after every $action

MERGE [Endpoint] WITH (SERIALIZABLE) AS T USING (VALUES  (0, 1, 0) ) AS S
(SourceIndex, EndpointId, EndpointUseInLiveIntegration)    ON T.EndpointId = S.EndpointId
WHEN MATCHED THEN UPDATE SET EndpointUseInLiveIntegration = 0 
OUTPUT CASE WHEN $action COLLATE DATABASE_DEFAULT = 'INSERT' THEN 'something' ELSE 'something else' END AS TestVal;

If the "COLLATE DATABASE_DEFAULT" is added to every MERGE command after the $action variable, it will gracefully handle contained databases. 

 


Replies

 
Matthias Sebastian Sort Dynamicweb Employee
Matthias Sebastian Sort
Reply
This post has been marked as an answer

Hi Scott,

I've created a bug --> https://dev.azure.com/dynamicwebsoftware/Dynamicweb/_workitems/edit/12540

and added the COLLATE DATABASE_DEFAULT all the places where we use that logic of "CASE WHEN $action = '".

I've only encountered this sql-error once, in my time @DW, so that might be why we haven't dived deep into this error msg before, but you shall have a thanks for finding it, and solved it for us :)

BR

Matthias Sort

Votes for this answer: 1
 
Scott Forsyth Dynamicweb Employee
Scott Forsyth
Reply

Hi Matthias,

That was fast! Thank's for doing that. Your changes look good to me.

Scott

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply
This post has been marked as an answer

Hi Scott

The problem #12540 on Azure SQL & SQL Server - collations

Now been fixed in Dynamicweb release version 9.15.4 
Get this from the download section https://doc.dynamicweb.dk/downloads/dynamicweb-9

Kind Regards
Care Support
Kristian Kirkholt

Votes for this answer: 1
 
Scott Forsyth Dynamicweb Employee
Scott Forsyth
Reply

Thanks Kristian!

 
Scott Forsyth Dynamicweb Employee
Scott Forsyth
Reply

Thanks Kristian!