This appears to be a conflict between the instance (i.e. server) -level collation and the collation being used in the
[master] database. Both
sys.dm_xe_sessions are system catalog views, and the collation of their
[name] fields should be the same.
sepupic had the O.P. execute the following:
select top 1 sql_variant_property(name, 'collation') from sys.server_event_sessions;
select top 1 sql_variant_property(name, 'collation') from sys.dm_xe_sessions;
The results were:
sys.server_event_sessions = Latin1_General_CI_AS
sys.dm_xe_sessions = SQL_Latin1_General_CP1_CI_AS
That difference should not be possible, but at least it explains the error message.
I requested that the O.P. execute the following to determine the instance-level collation:
O.P. replied with:
... the server collation is "SQL_Latin1_General_CP1_CI_AS". I was under the impression that the Server collation was whatever the master DB collation was. This server was installed from a Microsoft Azure image so the collation was changed from SQL_Latin1_General_CP1_CI_AS to Latin1_General_CI_AS.
Clearly something went wrong with the collation change process. I was able to reproduce the error by creating a database containing one table with one string column. I used a case-sensitive collation and that one column was also the Primary Key (meaning: a unique index). I added two rows:
N'a'. I then used the sqlservr.exe -q method (details linked below) of globally updating the collations to change the instance's collation to a different one, one that was case-insensitive. When the process tried to rebuild the PK, it failed as the case-insensitive collation rendered the second row not-unique from the first. But, the system DBs has already been updated. However, the instance level collation was not changed to the new collation as the process never completed.
To fix this, I believe the following would work:
- Detach all User DBs (to minimize impact of the operation: the user DB's are not a problem, and some columns might have different collations set that shouldn't be changed)
- Update the instance's collation using the
sqlservr.exe -q method
- Re-attach the User DB's