﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2012 / SQL Server 2012 -  T-SQL  / CONTAINED DATABASE OR NOT ... / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 19:37:55 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: CONTAINED DATABASE OR NOT ...</title><link>http://www.sqlservercentral.com/Forums/Topic1381503-3077-1.aspx</link><description>Yet another update on this issue:[url=http://connect.microsoft.com/SQLServer/feedback/details/772361/sqlserver-2012-contained-databases-collation-problem]connect.microsoft.com[/url][quote][b]Posted by Microsoft on 3/5/2013 at 11:50 AM[/b]Hello Marc, We have now fixed this bug in the next major version of SQL Server. Thanks for reporting the issue. -- Umachandar, SQL Programmability Team[/quote]So, waiting for the "next major version" :-)</description><pubDate>Wed, 06 Mar 2013 00:09:15 GMT</pubDate><dc:creator>marc.snoeys</dc:creator></item><item><title>RE: CONTAINED DATABASE OR NOT ...</title><link>http://www.sqlservercentral.com/Forums/Topic1381503-3077-1.aspx</link><description>nice follow-through! thanks for posting back</description><pubDate>Fri, 07 Dec 2012 10:09:52 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: CONTAINED DATABASE OR NOT ...</title><link>http://www.sqlservercentral.com/Forums/Topic1381503-3077-1.aspx</link><description>[url=http://connect.microsoft.com/SQLServer/feedback/details/772361/sqlserver-2012-contained-databases-collation-problem]connect.microsoft.com[/url][quote]Thanks for reporting the issue. The problem is due to the $action column metadata which is incompatible with the literal collation (string values 'INSERT' or 'DELETE'). This should work without requiring the collate clause. We will take a look at this.[/quote]</description><pubDate>Fri, 07 Dec 2012 00:34:49 GMT</pubDate><dc:creator>marc.snoeys</dc:creator></item><item><title>RE: CONTAINED DATABASE OR NOT ...</title><link>http://www.sqlservercentral.com/Forums/Topic1381503-3077-1.aspx</link><description>A further update ...I had a talk with Bob Beachemin about this issue ( and a few others stuff as well ).He had a look at it and his conclusions were:[quote]In fact, using any collation at random with the collate clause works, as long as you HAVE the collate clause[code]WHEN $action collate Albanian_BIN = 'INSERT'     THEN 'ADDED' WHEN $action collate Albanian_BIN = 'DELETE'     THEN 'REMOVED' [/code][/quote][quote]So you can, as far as I’m concerned, report it as a contained database problem (the fact that you MUST do the collation sounds like a bug) AND/OR a documentation problem (there is no classification of $action anywhere in BOL). The behavior likely has to do with the rules for comparison predicates when collate clause is not specified, and the fact the $action is probably special cased somewhere in the (SQL Server) code.[/quote]So I decided to report it on [url=https://connect.microsoft.com/SQLServer/feedback/details/772361/sqlserver-2012-contained-databases-collation-problem]CONNECT [/url]</description><pubDate>Wed, 28 Nov 2012 03:40:13 GMT</pubDate><dc:creator>marc.snoeys</dc:creator></item><item><title>RE: CONTAINED DATABASE OR NOT ...</title><link>http://www.sqlservercentral.com/Forums/Topic1381503-3077-1.aspx</link><description>[quote][b]marc.snoeys (11/14/2012)[/b][hr]Apparently there is a view where one can query for possible problems when changing to a CONTAINED database: SYS.DM_DB_UNCONTAINED_ENTITIES But a query on this view does not show this particular stored procedure.[/quote]I am not surprised. I would not expect the proc to be returned.[quote]All in all: I guess I'm forced to use the COLLATE-clause ...[/quote]I think that is the correct move. Here is code that will be portable between both contained as well as non-contained databases regardless of which collation you are using in the database:[code="sql"]WHEN $action COLLATE DATABASE_DEFAULT = 'DELETE' THEN 'REMOVED'[/code]</description><pubDate>Wed, 14 Nov 2012 17:23:29 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: CONTAINED DATABASE OR NOT ...</title><link>http://www.sqlservercentral.com/Forums/Topic1381503-3077-1.aspx</link><description>[quote][b]opc.three (11/13/2012)[/b][hr]Here is one possible explanation as to what is going on:In the contained database scenario $action is actually collated using the catalog default, i.e. Latin1_General_100_CI_AS_WS_KS_SC, per the table under the section [i]Contained Databases[/i] in [u][url=http://msdn.microsoft.com/en-us/library/ff929080.aspx]this article[/url][/u]. Try adding COLLATE [i]DATABASE_DEFAULT[/i] to collate $action in the CASE expression.[/quote]It strikes me as very odd that changing the containment type of a database results in different behavior in code: in this case the [b]$action[/b] field.But this is just a personal opinion (however a few colleagues do agree)I did a kind of an extension to this test-case:- Database [test] in CONTAINMENT TYPE=NONE- Create a stored procedure with the MERGE-statement above.- Try to change the CONTAINMENT TYPE=PARTIALThat resulted in following error, which is basically the same as in the first test-case.[code]Msg 468, Level 16, State 9, Procedure sp_TEST_CASE, Line 19Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "Latin1_General_100_CI_AS_KS_WS_SC" in the equal to operation.Msg 12813, Level 16, State 2, Line 2Errors were encountered in the procedure 'dbo.sp_TEST_CASE' during compilation of the object. Either the containment option of the database 'test' was changed, or this object was present in model db and the user tried to create a new contained database.Msg 12836, Level 16, State 1, Line 2ALTER DATABASE statement failed. The containment option of the database 'test' could not be altered because compilation errors were encountered during validation of SQL modules. See previous errors.Msg 5069, Level 16, State 1, Line 2ALTER DATABASE statement failed.[/code]Apparently there is a view where one can query for possible problems when changing to a CONTAINED database: SYS.DM_DB_UNCONTAINED_ENTITIES But a query on this view does not show this particular stored procedure.All in all: I guess I'm forced to use the COLLATE-clause ...</description><pubDate>Wed, 14 Nov 2012 03:42:05 GMT</pubDate><dc:creator>marc.snoeys</dc:creator></item><item><title>RE: CONTAINED DATABASE OR NOT ...</title><link>http://www.sqlservercentral.com/Forums/Topic1381503-3077-1.aspx</link><description>With containment type partial I also get the error.Can workaround with:[code="sql"]WHEN $action COLLATE SQL_Latin1_General_CP1_CI_AS = 'DELETE' THEN 'REMOVED'[/code]I found these articles which might be of help :[url]http://technet.microsoft.com/en-us/magazine/hh534404.aspx[/url][url]http://msdn.microsoft.com/en-us/library/ff929080.aspx[/url]</description><pubDate>Tue, 13 Nov 2012 07:08:44 GMT</pubDate><dc:creator>Dennis Post</dc:creator></item><item><title>RE: CONTAINED DATABASE OR NOT ...</title><link>http://www.sqlservercentral.com/Forums/Topic1381503-3077-1.aspx</link><description>[quote][b]marc.snoeys (11/13/2012)[/b][hr][quote][b]D.Post (11/13/2012)[/b][hr][quote]CASE  WHEN $action = 'INSERT' THEN 'ADDED'  WHEN $action = 'DELETE' THEN 'REMOVED'END ACTION[/quote]BUT: the question was rather why there is a difference in behavior between a PARTIALLY CONTAINED database and a NON-PARTIALLY CONTAINED database.[/quote]Here is one possible explanation as to what is going on:In the contained database scenario $action is actually collated using the catalog default, i.e. Latin1_General_100_CI_AS_WS_KS_SC, per the table under the section [i]Contained Databases[/i] in [u][url=http://msdn.microsoft.com/en-us/library/ff929080.aspx]this article[/url][/u]. Try adding COLLATE [i]DATABASE_DEFAULT[/i] to collate $action in the CASE expression.</description><pubDate>Tue, 13 Nov 2012 07:04:20 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: CONTAINED DATABASE OR NOT ...</title><link>http://www.sqlservercentral.com/Forums/Topic1381503-3077-1.aspx</link><description>Really appreciate you looking in/at this issue.The fact that you can reproduce the error by adding the COLLATE-clause is "as designed" in SQL Server.Forget the SQL 2008 track for now.The code is working in a SQL 2008 environment.The code also works in a SQL 2012 environment only when the database wherein you work has [b]CONTAINMENT TYPE NONE[/b]Did you have a try with the code against a database with [b]CONTAINMENT TYPE PARTIAL[/b] ?I also installed Service Pack I for SQL 2012, but the error still occurs</description><pubDate>Tue, 13 Nov 2012 06:47:45 GMT</pubDate><dc:creator>marc.snoeys</dc:creator></item><item><title>RE: CONTAINED DATABASE OR NOT ...</title><link>http://www.sqlservercentral.com/Forums/Topic1381503-3077-1.aspx</link><description>Your code works for me on both 2008 (10.50.1600) Enterprise2012 (10.0.2100) EvaluationBoth results are the same.[code="sql"]$action	ACTION	name	nameINSERT	ADDED	case	NULL[/code]I can reproduce your error by forcing an incorrect collation:[code="sql"]CASEWHEN $action COLLATE Latin1_General_CI_AS = 'INSERT' COLLATE SQL_Latin1_General_Cp437_BIN THEN 'ADDED'WHEN $action = 'DELETE' THEN 'REMOVED'END ACTION[/code][quote]Msg 468, Level 16, State 9, Line 12Cannot resolve the collation conflict between "SQL_Latin1_General_CP437_BIN" and "Latin1_General_CI_AS" in the equal to operation.[/quote]</description><pubDate>Tue, 13 Nov 2012 06:26:35 GMT</pubDate><dc:creator>Dennis Post</dc:creator></item><item><title>RE: CONTAINED DATABASE OR NOT ...</title><link>http://www.sqlservercentral.com/Forums/Topic1381503-3077-1.aspx</link><description>[quote][b]D.Post (11/13/2012)[/b][hr]Hi, The only thing I can think of is replacing:[code="sql"]ON	( Target.name = Source.name )[/code]with[code="sql"]ON	( Target.name COLLATE Latin1_General_CI_AS = Source.name COLLATE Latin1_General_CI_AS )[/code]Hope this helps.[/quote]Yes, and no ;-)First: I'm aware of the COLLATE clause to overcome differences in collating stuff.Second: the error isn't on the JOIN condition, but on the CASE-part where I check the $action field.So the COLLATE clause should go there.[quote]CASE  WHEN $action = 'INSERT' THEN 'ADDED'  WHEN $action = 'DELETE' THEN 'REMOVED'END ACTION[/quote]BUT: the question was rather why there is a difference in behavior between a PARTIALLY CONTAINED database and a NON-PARTIALLY CONTAINED database.As far as I'm concerned: this is a bug ;-)I've got SQL Server Days coming up, and I'm going to relate this issue to some of the speakers.</description><pubDate>Tue, 13 Nov 2012 03:28:06 GMT</pubDate><dc:creator>marc.snoeys</dc:creator></item><item><title>RE: CONTAINED DATABASE OR NOT ...</title><link>http://www.sqlservercentral.com/Forums/Topic1381503-3077-1.aspx</link><description>Hi, The only thing I can think of is replacing:[code="sql"]ON	( Target.name = Source.name )[/code]with[code="sql"]ON	( Target.name COLLATE Latin1_General_CI_AS = Source.name COLLATE Latin1_General_CI_AS )[/code]Hope this helps.</description><pubDate>Tue, 13 Nov 2012 03:17:01 GMT</pubDate><dc:creator>Dennis Post</dc:creator></item><item><title>CONTAINED DATABASE OR NOT ...</title><link>http://www.sqlservercentral.com/Forums/Topic1381503-3077-1.aspx</link><description>In a POC project I was looking into the SQL Server 2012 feature of partially contained databases.To my surprise I encountered an error where I didn't expect one.The code hereafter is a simplified test-case.Server Collation = Latin1_General_CI_ASCollation on database test is the same.Running the code when database test has CONTAINMENT = PARTIAL gives an error (see below)Running the code when database test has CONTAINMENT = NONE doesn't give any error.So it seems that there is some change in collation behavior depending on the CONTAINMENT type ...[code="plain"]USE [master]GOALTER DATABASE [test] SET CONTAINMENT = PARTIAL WITH NO_WAIT -- WILL RESULT IN ERROR-- ALTER DATABASE [test] SET CONTAINMENT = NONE WITH NO_WAIT -- WILL WORKGOUSE [test]GODROP TABLE TEST_CASEGOCREATE TABLE TEST_CASE	(	name	varchar(10)		NOT NULL	,	CONSTRAINT PK_LOG_FILTER_PK PRIMARY KEY CLUSTERED (name)	)GO;MERGE INTO TEST_CASE	TargetUSING	(		SELECT	'case'	AS name		)	SourceON	( Target.name = Source.name )WHEN NOT MATCHED BY TARGET	THEN	INSERT ( name ) VALUES ( Source.name )WHEN NOt MATCHED BY SOURCE	THEN	DELETEOUTPUT	$action	,	CASE			WHEN $action = 'INSERT' THEN 'ADDED'			WHEN $action = 'DELETE' THEN 'REMOVED'		END ACTION	,	inserted.name	,	deleted.name;[/code][quote]Msg 468, Level 16, State 9, Line 12Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "Latin1_General_100_CI_AS_KS_WS_SC" in the equal to operation.[/quote]Can anyone give me a satisfactory explanation  ...</description><pubDate>Tue, 06 Nov 2012 05:01:28 GMT</pubDate><dc:creator>marc.snoeys</dc:creator></item></channel></rss>