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.

SQLException: Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" in the equal to operation.

See original GitHub issue

Driver version or jar name

6.3.6-preview

SQL Server version

SQL Server 2008, database schema in server server 2005 compatibility mode

Client operating system

Windows (but this should not matter)

Java/JVM version

1.8 (but this should not matter)

Table schema

any

Problem description

While using class SQLServerDatabaseMetaData the execution of the follwing query in Method getResultSetForForeignKeyInformation(…) leads an exception:

stmt.addBatch("insert into " + foreign_keys_combined_tableName + " select " + sys_foreign_keys + ".name, " + sys_foreign_keys + ".delete_referential_action_desc, " + sys_foreign_keys + “.update_referential_action_desc,” + fkeys_results_tableName + “.PKTABLE_QUALIFIER,” + fkeys_results_tableName + “.PKTABLE_OWNER,” + fkeys_results_tableName + “.PKTABLE_NAME,” + fkeys_results_tableName + “.PKCOLUMN_NAME,” + fkeys_results_tableName + “.FKTABLE_QUALIFIER,” + fkeys_results_tableName + “.FKTABLE_OWNER,” + fkeys_results_tableName + “.FKTABLE_NAME,” + fkeys_results_tableName + “.FKCOLUMN_NAME,” + fkeys_results_tableName + “.KEY_SEQ,” + fkeys_results_tableName + “.UPDATE_RULE,” + fkeys_results_tableName + “.DELETE_RULE,” + fkeys_results_tableName + “.FK_NAME,” + fkeys_results_tableName + “.PK_NAME,” + fkeys_results_tableName + ".DEFERRABILITY from " + sys_foreign_keys + " right join " + fkeys_results_tableName + " on " + sys_foreign_keys + “.name=” + fkeys_results_tableName + “.FK_NAME”);

Expected behavior and actual behavior

Excected behaviour: query executes without exception and returns foreign key metadata. Actual behavior: SQLException: Cannot resolve the collation conflict between “SQL_Latin1_General_CP1_CI_AS” and “Latin1_General_CI_AS” in the equal to operation.

Repro code

I think the problem is that the database server collection is set to SQL_Latin1_General_CP1_CI_AS but the database collection is Latin1_General_CI_A. Since i think my jdbc connection inherits collation setting from database/schema instance. The table fkeys_results_tableName is created with collation Latin1_General_CI_AS but the system table sys.foreign_keys is created with collation SQL_Latin1_General_CP1_CI_AS. Therefore the equal operator in the expression ( sys_foreign_keys + “.name=” + fkeys_results_tableName + “.FK_NAME”) can not be executed without additions.

Proposed fix: adding suffix " collate database_default" to sql query like this: … sys_foreign_keys + " right join " + fkeys_results_tableName + " on " + sys_foreign_keys + “.name=” + fkeys_results_tableName + “.FK_NAME” + " collate database_default"

In my tests this resolved the issue.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rene-yecommented, May 3, 2018

#677 has now been merged. Closing the issue.

1reaction
rene-yecommented, Apr 16, 2018

Hi @thfranken @nvdweem @tjlee, we recently had to change that part of the driver and thought now would be a good time to address this issue. I’m adding the solution to this issue along with the PR addressing #665. You can test the changes by cloning the branch from PR #677 or downloading the jars below. Jars for testing.zip

Read more comments on GitHub >

github_iconTop Results From Across the Web

sql server - Cannot resolve the collation conflict between ...
The root cause is that the sql server database you took the schema from has a collation that differs from your local ...
Read more >
Cannot resolve the collation conflict between ... - Microsoft Learn
Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
Read more >
T-SQL- Error: “Cannot resolve the collation conflict between…”
"SQL_Latin1_General_CP1_CI_AS" in the equal to operation. This can occur in SQL Server Reporting Services (SSRS) when using a data source that ...
Read more >
Error Cannot resolve the collation conflict between SQL Latin1 ...
When running the query I am getting this message: Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Arabic_CI_AS ...
Read more >
Cannot resolve the collation conflict between ... - IBM
Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
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