{"id":767,"date":"2007-09-19T18:22:00","date_gmt":"2007-09-19T18:22:00","guid":{"rendered":"\/blogs\/bobb\/post\/SQLCLR-and-system-functionality-in-SQL-Server-2008-part-2.aspx"},"modified":"2014-01-20T12:14:17","modified_gmt":"2014-01-20T20:14:17","slug":"sqlclr-and-system-functionality-in-sql-server-2008-part-2","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/","title":{"rendered":"SQLCLR and system functionality in SQL Server 2008 &#8211; part 2"},"content":{"rendered":"<p>\nI&#39;m running with SQLCLR on, because I&#39;d like to see the interaction between system SQLCLR code and appdomains. See the previous blog posting for an explanation of why this doesn&#39;t affect my system functions. First, I bring up SQL Server 2008 &quot;fresh&quot;, open SQL log in SSMS, and start a profiler trace to catch Assembly Loading events. SQLCLR is nowhere to be seen.\n<\/p>\n<p>\nUSE TEMPDB<br \/>\nGO\n<\/p>\n<p>\nSELECT * FROM sys.assemblies;<br \/>\nGO\n<\/p>\n<p>\nThe assembly list contains an entry for Microsoft.SqlServer.Types, that&#39;s the assembly that contains the system UDTs. It actually lives&nbsp;in the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms190940.aspx\">resource database<\/a>, but shows up in system metadata lists for every database. In the SQL Server log, just listing the assemblies in a database produces:\n<\/p>\n<p>\nCommon language runtime (CLR) functionality initialized using&#8230;<br \/>\nAppDomain 2 (32767.sys[runtime].1) created\n<\/p>\n<p>\nDatabase 32767 is the resource database, although its not for the most part directly visible in SQL Server 2005 metadata or in SSMS.\n<\/p>\n<p>\n.NET appdomains are created on a per-database basis, currently one appdomain per assembly owner. So this functionality runs under an appdomain created for the owner &quot;sys&quot;. The assembly is actually owned by principal_id 4, which is INFORMATION_SCHEMA according to sys.database_principals. But sys.schemas indicates that the sys schema is owned by principal_id 4 as well, INFORMATION_SCHEMA schema is owned by principal 3. They&#39;re likely referring to principal_id in the resource database, not the current database. Sys.assemblies also has this assembly marked as is_user_defined = 0 (false). And, the assembly has a safety level of UNSAFE. Hmmm&#8230;\n<\/p>\n<p>\nKnowing how SQLCLR exception escalation works, I was concerned by the system assembly being UNSAFE. It is&nbsp; running in its own appdomain. However, when I looked at the SQL Server log for the SQLCLR message, another seemingly unrelated message attracted my attention:\n<\/p>\n<p>\nUsing xpstar.dll version 2007.100.1049 to execute extended stored procedure xp_instance_regread&#8230;\n<\/p>\n<p>\nSQL Server internals have always included extended stored procedures to perform system functions. User-written extended stored procedures can cause problems if poorly written, but this one (xp_instance_regread)&nbsp;was written by the SQL Server team, its part of SQL Server itself. Hmmm&#8230;so is Microsoft.SqlServer.Types part of SQL Server. And .NET code has more built in safeguards than unmanaged code. And BOL has indicated since SQL Server 2005 betas:\n<\/p>\n<p>\n&quot;This feature (i.e. extended stored procedures) will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use CLR Integration instead.&quot;\n<\/p>\n<p>\nSo I guess its OK, they&#39;re taking their own advise. And this assembly has been tested with SQL Server for hardening, it doesn&#39;t produce the error message that cataloging, say, System.Runtime.Remoting, does.\n<\/p>\n<p>\nOne final item. SQL Profiler does not load Microsoft.SqlServer.Types.dll just because I execute &quot;select * from sys.assemblies&quot;, but profiler reports:\n<\/p>\n<p>\nAssembly Load Failed for requested assembly system.enterpriseservices, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a, processorarchitecture=x86 with Error code: 0x80070002\n<\/p>\n<p>\nPerhaps there&#39;s a stray assembly dependency somewhere in CTP4. System.EnterpriseServices is not on the list of tested assemblies either, so it shouldn&#39;t load automatically.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#39;m running with SQLCLR on, because I&#39;d like to see the interaction between system SQLCLR code and appdomains. See the previous blog posting for an explanation of why this doesn&#39;t affect my system functions. First, I bring up SQL Server 2008 &quot;fresh&quot;, open SQL log in SSMS, and start a profiler trace to catch Assembly [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,38],"tags":[],"class_list":["post-767","post","type-post","status-publish","format-standard","hentry","category-sql-server-2008","category-sqlclr"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQLCLR and system functionality in SQL Server 2008 - part 2 - Bob Beauchemin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQLCLR and system functionality in SQL Server 2008 - part 2 - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"I&#039;m running with SQLCLR on, because I&#039;d like to see the interaction between system SQLCLR code and appdomains. See the previous blog posting for an explanation of why this doesn&#039;t affect my system functions. First, I bring up SQL Server 2008 &quot;fresh&quot;, open SQL log in SSMS, and start a profiler trace to catch Assembly [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2007-09-19T18:22:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-01-20T20:14:17+00:00\" \/>\n<meta name=\"author\" content=\"Bob Beauchemin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bob Beauchemin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/\",\"name\":\"SQLCLR and system functionality in SQL Server 2008 - part 2 - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2007-09-19T18:22:00+00:00\",\"dateModified\":\"2014-01-20T20:14:17+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server 2008\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/sql-server-2008\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQLCLR and system functionality in SQL Server 2008 &#8211; part 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\",\"name\":\"Bob Beauchemin\",\"description\":\"SQL Server Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\",\"name\":\"Bob Beauchemin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"caption\":\"Bob Beauchemin\"},\"sameAs\":[\"http:\/www.sqlskills.com\/blogs\/bobb\/\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQLCLR and system functionality in SQL Server 2008 - part 2 - Bob Beauchemin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/","og_locale":"en_US","og_type":"article","og_title":"SQLCLR and system functionality in SQL Server 2008 - part 2 - Bob Beauchemin","og_description":"I&#39;m running with SQLCLR on, because I&#39;d like to see the interaction between system SQLCLR code and appdomains. See the previous blog posting for an explanation of why this doesn&#39;t affect my system functions. First, I bring up SQL Server 2008 &quot;fresh&quot;, open SQL log in SSMS, and start a profiler trace to catch Assembly [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/","og_site_name":"Bob Beauchemin","article_published_time":"2007-09-19T18:22:00+00:00","article_modified_time":"2014-01-20T20:14:17+00:00","author":"Bob Beauchemin","twitter_misc":{"Written by":"Bob Beauchemin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/","name":"SQLCLR and system functionality in SQL Server 2008 - part 2 - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2007-09-19T18:22:00+00:00","dateModified":"2014-01-20T20:14:17+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/sqlclr-and-system-functionality-in-sql-server-2008-part-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"SQL Server 2008","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/sql-server-2008\/"},{"@type":"ListItem","position":3,"name":"SQLCLR and system functionality in SQL Server 2008 &#8211; part 2"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/","name":"Bob Beauchemin","description":"SQL Server Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e","name":"Bob Beauchemin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","caption":"Bob Beauchemin"},"sameAs":["http:\/www.sqlskills.com\/blogs\/bobb\/"],"url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/comments?post=767"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/767\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}