{"id":1018,"date":"2004-10-02T07:05:00","date_gmt":"2004-10-02T07:05:00","guid":{"rendered":"\/blogs\/bobb\/post\/How-SQLCLR-works-when-its-disabled.aspx"},"modified":"2004-10-02T07:05:00","modified_gmt":"2004-10-02T07:05:00","slug":"how-sqlclr-works-when-its-disabled","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/how-sqlclr-works-when-its-disabled\/","title":{"rendered":"How SQLCLR works when its disabled"},"content":{"rendered":"<p>\nI heard that when SQL Server 2005 ships, SQLCLR (the ability to execute .NET code in SQL Server) will be disabled by default. This is part of an &quot;off-by-default&quot; philosophy that goes &quot;because there are so many revolutionary new features in SQL Server 2005, and DBAs and programmers may not have had time to digest the ramifications of using all of them, you&#39;ll have to enable them, one at a time, when you understand them. They&#39;ll be off until you make a conscious decision to turn them on&quot;. IIS 6.0 works this way with its programming extensions; for example, you must enable using ASP.NET or ASP classic.\n<\/p>\n<p>\nThought I&#39;d better look up how to turn it on and off:\n<\/p>\n<p>\nEXEC sp_configure &#39;show advanced options&#39;, 1<br \/>\nGO<br \/>\nRECONFIGURE<br \/>\nGO<br \/>\n&#8212; turn it on<br \/>\nEXEC sp_configure &#39;clr enabled&#39;, 1<br \/>\nGO<br \/>\nRECONFIGURE<br \/>\nGO\n<\/p>\n<p>\n&#8212; or turn it off<br \/>\nEXEC sp_configure &#39;clr enabled&#39;, 0<br \/>\nGO<br \/>\nRECONFIGURE<br \/>\nGO\n<\/p>\n<p>\nThat was easy. I turned it off and restarted SQL Server wanting to see what error message it would produce. Some folks I&#39;ve spoken to claim to want it off even though they understand it, because SQLCLR loads the .NET runtime. This takes about 10 meg of memory, from SQL Server&#39;s &quot;normal&quot; memory pool (it does not use the MEM-to-leave pool as in-SQL Server COM components do). Turning SQLCLR off did not cause the CLR to be unloaded (or at least it didn&#39;t produce a log message to that effect). So I wanted to see if I could get the .NET runtime to load if SQLCLR is disabled. Started with:\n<\/p>\n<p>\nCREATE ASSEMBLY foo FROM &#39;c:\\foo.dll&#39;<br \/>\nGO\n<\/p>\n<p>\nEven though foo.dll doesn&#39;t exist on my machine, this statement normally causes to .NET runtime to load. Even though it errors out with the message:\n<\/p>\n<p>\nMsg 6501, Level 16, State 7, Line 1<br \/>\nCREATE ASSEMBLY failed because it could not open the physical file &#39;c:\\foo.dll&#39;: 2(The system cannot find the file specified.).\n<\/p>\n<p>\nThe reason that the .NET runtime is loaded in this case in that SQLCLR internally calls Assembly.Load(&quot;c:\\foo.dll&quot;) (or some variation) to load the assembly and validate it using the reflection APIs. Both Assembly.Load and reflection are, of course, managed code, requiring the runtime.I expected a different error this time, because SQLCLR is disabled. Same error. And the log revealed that the .NET runtime had been loaded. Even though SQLCLR is disbaled. Hmm&#8230;.didn&#39;t expect that. Just to see how far I could go, I got out a real assembly and ran:\n<\/p>\n<p>\nCREATE ASSEMBLY MetricConverter<br \/>\n&nbsp;FROM &#39;c:\\types\\metricconverter.dll&#39;\n<\/p>\n<p>\nThis succeeded, I&#39;d cataloged my assembly. Hmm&#8230;&nbsp;How about:\n<\/p>\n<p>\nCREATE FUNCTION convertme(@a FLOAT)<br \/>\nRETURNS FLOAT<br \/>\nAS EXTERNAL NAME MetricConverter.[DM.EssentialYukon.MetricConverter].KilometersToMiles\n<\/p>\n<p>\nThis succeeded too. At this point I started to doubt that I&#39;d actually turned SQLCLR off. Then I ran:\n<\/p>\n<p>\nDECLARE @f FLOAT<br \/>\nSET @f = dbo.convertme(42)<br \/>\nPRINT @f\n<\/p>\n<p>\nThis failed as expected:\n<\/p>\n<p>\nMsg 6263, Level 16, State 1, Line 2<br \/>\nExecution of user code in the .NET Framework is disabled.\n<\/p>\n<p>\nSo the &#39;clr enabled&#39; option disables *running* user CLR code in SQL Server 2005. It doesn&#39;t diable loading the runtime. Or cataloging database objects, like assemblies and UDFs, that use SQLCLR. It&#39;s a convenience to allow DBAs (usually the only ones with this permission) to catalog these objects before allowing the actual user CLR code to be executed. If you&#39;re really concerned about the 10 meg, don&#39;t use the DDL. Note to self: test *everything* before making assumptions. I guess that goes along with &ldquo;off-by-default&rdquo;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I heard that when SQL Server 2005 ships, SQLCLR (the ability to execute .NET code in SQL Server) will be disabled by default. This is part of an &quot;off-by-default&quot; philosophy that goes &quot;because there are so many revolutionary new features in SQL Server 2005, and DBAs and programmers may not have had time to digest [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,38],"tags":[],"class_list":["post-1018","post","type-post","status-publish","format-standard","hentry","category-sql-server-2005","category-sqlclr"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How SQLCLR works when its disabled - 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\/how-sqlclr-works-when-its-disabled\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How SQLCLR works when its disabled - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"I heard that when SQL Server 2005 ships, SQLCLR (the ability to execute .NET code in SQL Server) will be disabled by default. This is part of an &quot;off-by-default&quot; philosophy that goes &quot;because there are so many revolutionary new features in SQL Server 2005, and DBAs and programmers may not have had time to digest [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/how-sqlclr-works-when-its-disabled\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2004-10-02T07:05:00+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\/how-sqlclr-works-when-its-disabled\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/how-sqlclr-works-when-its-disabled\/\",\"name\":\"How SQLCLR works when its disabled - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2004-10-02T07:05:00+00:00\",\"dateModified\":\"2004-10-02T07:05:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/how-sqlclr-works-when-its-disabled\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/how-sqlclr-works-when-its-disabled\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/how-sqlclr-works-when-its-disabled\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server 2005\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/sql-server-2005\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How SQLCLR works when its disabled\"}]},{\"@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":"How SQLCLR works when its disabled - 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\/how-sqlclr-works-when-its-disabled\/","og_locale":"en_US","og_type":"article","og_title":"How SQLCLR works when its disabled - Bob Beauchemin","og_description":"I heard that when SQL Server 2005 ships, SQLCLR (the ability to execute .NET code in SQL Server) will be disabled by default. This is part of an &quot;off-by-default&quot; philosophy that goes &quot;because there are so many revolutionary new features in SQL Server 2005, and DBAs and programmers may not have had time to digest [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/how-sqlclr-works-when-its-disabled\/","og_site_name":"Bob Beauchemin","article_published_time":"2004-10-02T07:05:00+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\/how-sqlclr-works-when-its-disabled\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/how-sqlclr-works-when-its-disabled\/","name":"How SQLCLR works when its disabled - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2004-10-02T07:05:00+00:00","dateModified":"2004-10-02T07:05:00+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/how-sqlclr-works-when-its-disabled\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/how-sqlclr-works-when-its-disabled\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/how-sqlclr-works-when-its-disabled\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"SQL Server 2005","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/sql-server-2005\/"},{"@type":"ListItem","position":3,"name":"How SQLCLR works when its disabled"}]},{"@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\/1018","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=1018"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/1018\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=1018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=1018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=1018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}