1

I have created the .bak file from my local database (MSSQL SERVER 2012) and restored it on live server (MSSQL Server 2012). It is working but some the stored_procedures are not executing and are generating error:

Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AI" in the equal to operation

I do not have any idea what this error is and how to resolve it?

I have thousands of stored_procedures.How to resolve this issue in all stored procedures?

Dev
  • 73
  • 10
  • This is probably compatibility versions. for now you can look up 'COLLATE DATABASE_DEFAULT' and use this in your query or you can fix the compatibility version so that they match. – Rich Benner Jun 16 '16 at 10:08
  • Do I have to do it every problematic `stored_procedure`? – Dev Jun 16 '16 at 10:20
  • If you want to do it at a query level, yes. Otherwise just change the compatibility mode to match what it was before. – Rich Benner Jun 16 '16 at 10:21
  • how can I change compatibility mode? I think it will be better than changing 1000 of procedures. – Dev Jun 16 '16 at 10:23
  • @Dev [Set or Change the Database Collation](https://msdn.microsoft.com/en-gb/library/ms175835(v=sql.110).aspx) – Chris Pickford Jun 16 '16 at 10:24
  • Possible duplicate of [Cannot resolve the collation conflict between "SQL\_Latin1\_General\_CP1\_CI\_AS" and "Latin1\_General\_CI\_AS" in the equal to operation](http://stackoverflow.com/questions/1607560/cannot-resolve-the-collation-conflict-between-sql-latin1-general-cp1-ci-as-and) – MusicLovingIndianGirl Jun 16 '16 at 10:25
  • @ChrisPickford ,WIll it work for all stored_procedures?I am new to these type of advanced settings. – Dev Jun 16 '16 at 10:37
  • These settings will change it for everything, use the link @ChrisPickford posted. – Rich Benner Jun 16 '16 at 10:40
  • @RichBenner, it dodn't worked `ALTER DATABASE myDBName COLLATE collatename ;` procedure still generating error – Dev Jun 16 '16 at 10:46
  • You appear to be linking two databases that are using a different collation method. Make sure they're both set to the same. Also, I'd speak to your DBA about this. You do have a DBA don't you? – Rich Benner Jun 16 '16 at 10:52
  • @RichBenner, don't have a DBA. – Dev Jun 16 '16 at 11:25
  • @Dev google 'Brent Ozar Accidental DBA' and sign up to the emails, they're really useful and should help your skills. Looks like you're the DBA now – Rich Benner Jun 16 '16 at 11:37
  • 1
    Possible duplicate of [Cannot resolve the collation conflict between](http://stackoverflow.com/questions/17616620/cannot-resolve-the-collation-conflict-between) – BIDeveloper Jun 16 '16 at 12:00

1 Answers1

2

The issue is likely to be a difference in collation settings between your "local" SQL Server and your "live" SQL Server and as a result the wrong collation being used by your database and database objects.

You need to pay close attention to server parameters (ANSI settings, Collation etc) when installing a development server to ensure they fully match your production server. The same applies to the database parameters. See this somewhat old but still relevant article about how collation settings work.

You can find out the current collation settings either through SSMS or by running the following queries (see MSDN):

-- Server Collation Setting
SELECT CONVERT (varchar, SERVERPROPERTY('collation'));

-- Database Collation Settings
SELECT name, collation_name FROM sys.databases;

-- Table column Collation Settings
SELECT t.name, c.name AS ColName, *
FROM sys.tables AS t
    INNER JOIN sys.columns AS c ON t.object_id = c.object_id
WHERE not collation_name is NULL
ORDER BY t.name, column_id

You have two choices in how to resolve this:

Change collation setting of your database and all objects

To resolve this collation difference on the "live" environament you will need to:
1. Change collation of your database to match the collation setting of the production server
2. Change collation of every column in your tables / views etc (see this post)

The easiest solution is to just recreate every single object in the database (after you change DB collation) with the correct collation setting.

Modify your code

The 2nd option is what people have suggested in comments, namelly explicitly specify collation setting "everywhere" in your code. This option should be used as a last resort or when absoluely necessary (cannot think of a reason when this may be necessary).

Miscellaneous

It is also possible to change collation of the server but this is not really an option.

Community
  • 1
  • 1
Alex
  • 4,885
  • 3
  • 19
  • 39