SQL CLR is Microsoft's Common-Language-Runtime implementation for SQL Server. Use this tag for questions about how to implement and troubleshoot SQLCLR on Microsoft SQL Server.

learn more… | top users | synonyms (1)

16
votes
3answers
770 views

Setting up a central CLR stored procedure / function respository library for internal stored procs in other databases to use?

I would like to use code that I developed in C# CLR to be used in all of the databases on the system so that I don't have to set each to trustworthy and turn CLR on and keep a bunch of the same code ...
12
votes
2answers
545 views

Crashing CLR on SQL Server 2014 (windows 2012R2)

I have this small CLR that does a RegEX function on a string in columns. When running on SQL Server 2014 (12.0.2000) on Windows Server 2012R2 the process crashes with Msg 0, Level 11, State 0, ...
10
votes
2answers
3k views

Do SQL Server Express Editions support CLR procedures?

Do SQL Server Express Editions (2005, and 2008) have support for installing, enabling and running CLR Stored procedures and functions.
9
votes
2answers
1k views

Other than restarting SQL Server, is there any way to force the SQLCLR AppDomain to be reset?

I want to force the AppDomain being used by SQLCLR to be reset. How can I do that besides restarting the SQL Server instance?
6
votes
3answers
6k views

Assembly 'system.web, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.' was not found in the SQL catalog

I am trying to deploy a SQL CLR function using the HTTPUtility.UrlDecode method of System.Web but I can't get it to deploy. Error received: .Net SqlClient Data Provider: Msg 6503, Level 16, State ...
6
votes
1answer
100 views

How to better use CLR Function from performance point of view (repeat inside each DB or have general function)?

I asked a question about validation of XML using XSD schema inside SQL Server 2012 (see link). I understand (as I suspected) that I need to use CLR Function. The function will get XSD schema text and ...
6
votes
1answer
443 views

SQL Server: How to get the responsiveness of a trigger, without blocking the transaction that fires the trigger?

On a thread today I posed a desire to get code to execute immediately when a record is inserted rather than resorting to polling. Triggers are powerful tools, yet dangerous places to put real code, ...
5
votes
1answer
2k views

Reference assembly in sqlproj not being deployed to server

I have a Visual Studio 2013 Database Project which takes a modified version of fastJSON as a reference. I selected Generate DDL in the reference properties as shown in this screenshot: And in the ...
5
votes
1answer
10k views

How to grant a user UNSAFE ASSEMBLY permission

How can we assign a user , e.g.: the database owner (DBO) the UNSAFE ASSEMBLY permission? I'm asking it to enable a user to create an assembly and don't know the SA password, so EXEC sp_changedbowner ...
5
votes
1answer
1k views

Calling a .NET method in a SQL Server script

In the data migration process, I need to convert some columns values form the source system before writing to the target table. I've been provided with a Csharp code which reads a string and do the ...
5
votes
1answer
600 views

Is there anyway to make sql server search the master database for SQLCLR stored procedures before the current one?

For T-SQL stored procedures with the prefix sp_, SQL Server will search for and user a procedure in the master database before the current one. This does not appear to be the case with a SQLCLR stored ...
5
votes
1answer
286 views

Can CLR execution continue after 'THROW' is encountered in T-SQL?

I am calling a T-SQL stored procedure from a CLR stored procedure. and the THROW statement in T-SQL stops the execution of CLR without going into the catch block. Is there something I can change in my ...
5
votes
1answer
177 views

Why does dm_os_memory_clerks have MEMORYCLERK_SQLCLR values on one NUMA node?

We are using a SQLCLR stored procedure for service broker activation, and I want to monitor the memory used by the CLR code. Looking at sys.dm_os_memory_clerks, I see that only NUMA node 1 has any ...
5
votes
1answer
598 views

Understanding MS SQL Server Date Types

Consider the following: declare @dt datetime, @dt2 datetime2, @d date set @dt = '2013-01-01' set @dt2 = '2013-01-01' set @d = '2013-01-01' select convert(varbinary, @dt) as dt, ...
5
votes
1answer
126 views

dm_exec_describe_first_result_set_for_object for multiple result sets

Does a procedure exist to return metadata for all result sets in a stored procedure? Something like sys.dm_exec_describe_first_result_set_for_object, but for all result sets? Eventually, I will want ...
4
votes
1answer
225 views

How can “HierarchyID” type work when “CLR” is disabled?

The following statement sp_configure 'clr enabled' returns: name minimum maximum config_value run_value clr enabled 0 1 0 0 I assume this means there are no CLR ...
4
votes
1answer
482 views

Suggest better design pattern for reverse DNS lookups

I'm working on a project where I need to look up the hostnames associated with IP addresses who were logged making HTTP requests. The lookups currently happen as part of a daily ETL job. The current ...
4
votes
1answer
625 views

GZipStream/DeflateStream compressions alternatives

I have created a simple CLR functions for compressing/decompressing NVARCHAR columns: [SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true)] public static SqlBinary Compress( string ...
4
votes
1answer
89 views

Validate XML using XSD inside TSQL function in SQL Server 2012?

I need to validate XML using XSD inside TSQL. To make this task semi automated I need to do this inside TSQL function. To make validation I have to set value to XML and if it is not valid I will ...
4
votes
1answer
1k views

How do I create a CLR UDF with external name specifying namespace, class, and subclass?

I am creating a CLR UDF using external name and second level nested class names seem not to be permitted. Is this the case? When using the following syntax and including a first level class name and ...
4
votes
1answer
255 views

triggers - using the inserted / deleted tables in Dynamic SQL

Within a trigger, I'm trying to create a unique table name (using the NEWID()) which I can store the data that is found in the inserted and deleted tables. Declare @NewID varchar(50) = ...
3
votes
3answers
219 views

Can I run a CLR Stored Procedure on a different server than the database instance?

I want to add a trigger whenever a row is inserted into a certain table. The trigger will fire off a CLR stored procedure which will do things other than database work, such as write a JSON string to ...
3
votes
2answers
1k views

Security or performance risks using SQL CLR [closed]

Are there any particular security or performance risks in using the CLR in SQL Server ?
3
votes
2answers
492 views

Is there a SQL Server 2008 R2 specific target for SSDT projects?

I am making a SQLCLR stored procedure in Visual Studio 2012. I have these options for target platform: Is there not a SQL Server 2008 R2 specific option? Is this because SQL 2008 R2 shares the same ...
3
votes
2answers
1k views

Migrating CLR Assemblies

I am migrating a SQL Server 2008R2 database to a new server. (also 2008R2) There are a number of CLR assemblies on the server. Will these automatically migrate with the database or will I have to ...
3
votes
1answer
5k views

resource wait SQLCLR - wait_type CLR_SEMAPHORE by SPID 0

UPDATE In the comments under Aaron's post is an extensive explanation why I want to find this out, please read it if you want to know. The system is running some ETL, reporting services and a ...
3
votes
1answer
26 views

SQL 2012 CLR error: “The context transaction which was active before entering …”?

I am experience strange error with SQL 2012 and CLR: The context transaction which was active before entering user defined routine, trigger or aggregate "My routine" has been ended inside of ...
3
votes
2answers
4k views

App domain is marked for unload due to memory pressure

In my sql server log (2005 SP4) I have this message every couple of seconds : "AppDomain XXX [DataBase.dbo[runtime], YYY] is marked for unload due to memory pressure" Our server : Windows Server ...
3
votes
1answer
248 views

Mathematical method for spotting irregularity in numbers flow

I am trying to build an engine which is going to predict orders for items inside shop. Three main variables are: Time-dates (x-axe etc 1.1.2013,1.2.2013 etc I do calculation one per day) Available ...
2
votes
2answers
190 views

Visual Studio DAC with Schemabound View containing hierarchyid::GetRoot() - Two part name needed?

In Visual Studio, when trying to create a DAC which has a schemabound view which contains hierarchyid::GetRoot() this error is generated and the project does not build. However, the t-sql is ok as if ...
2
votes
2answers
401 views

AppDomain 2 (mssqlsystemresource.dbo[runtime].1) is marked for unload due to memory pressure message in SQL Server Log

From last two days I can see following in SQL Server errorlog. AppDomain 2 (mssqlsystemresource.dbo[runtime].1) unloaded. & AppDomain 2 (mssqlsystemresource.dbo[runtime].1) is marked for unload ...
2
votes
1answer
405 views

How to capture PRINT statements from TSQL called by CLR stored procedure

I have a CLR stored procedure that (among other things) calls a TSQL stored procedure. The TSQL stored procedure runs some dynamic SQL, and it prints the SQL before it runs for debugging purposes. ...
2
votes
1answer
406 views

Getting Visual Studio to deploy a UDF to Return NVARCHAR(MAX)

I have a SQLCLR stored procedure with the following signature in Visual Studio 2013: [SqlFunction(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] public static ...
2
votes
1answer
962 views

Counting the number of calls of a stored procedure

I have a CLR sp in SQL Server 2008 R2, and I want to count how often it is called, in order to create a statistic on data quality. (The sp allows manual correction of data). How can I let a counter ...
2
votes
2answers
323 views

Export a table and zip with password

I would like, from TSQL, to use a view to extract data from a table, output it with BCP, then use non 3rd party tools to ZIP it with a password and AES encryption. Optionnally, I could use a 3rd party ...
2
votes
2answers
66 views

CLR/C# equivalent to XACT_STATE()

I am porting a set of T-SQL stored procedures to C#/CLR. In the T-SQL, we use XACT_STATE() to determine if an error requires rolling back to a savepoint or rolling back the transaction entirely. I ...
2
votes
1answer
329 views

In a SSDT project how to avoid redeploying the assembly?

I have a SSDT project that has a few sql clr elements. They rarely get altered but every time I redeploy my db project it decides it must drop the assembly and recreate it. I think its somewhat ...
2
votes
1answer
456 views

Variable numbers of parameters in a SqlClr UDF or Stored Proc

Lets say I have the following signature for a CLR Stored Proc or UDF: [Public] public static void RaisError( string message, short severity, short state, params object[] args) ...
2
votes
1answer
468 views

How to access external DLL's static methods that incorporate output parameters in SQL Server

I know how to load a CLR DLL in SQL Server and access to its static methods which does not incorporate output parameters in their method signatures but what I cannot realize is how I can use methods ...
2
votes
2answers
593 views

SQL server job deployment

I have a SQL Server job which has got different steps, including running a SSIS package. Currently it is on my PC (my local instance). I should deploy it to UAT and assume some steps need to be ...
2
votes
1answer
38 views

SQLCLR assembly throws error when multiple queries run simultaneously

I have been using SimMetrics to implement the QGramsDistance search in SQL Server. The SimMetrics is used as a SQL CLR assembly. The search results are promising and everything was well, until of ...
2
votes
0answers
721 views

Passing NULL xml value to a certain CLR stored function crashes it when called in a certain way

Consider a CLR stored procedure that accepts an XML parameter and calls another stored procedure in the same schema: [SqlFunction(DataAccess = DataAccessKind.Read, IsDeterministic = false, ...
1
vote
2answers
2k views

Storing IP addresses - varchar(45) vs varbinary(16)

I am going to create a table with two fields - ID as BIGINT and IPAddress as either varchar(45) or varbinary(16). The idea is to store all unique IP addresses and use a reference ID instead the actual ...
1
vote
1answer
88 views

Significance of has_unchecked_assembly_data due to a persisted computed column after changing compatibility level?

This database has a persisted computed column, which is computed by calling a .NET function. When changing compatibility from MSSQL 2005 to 2012, I was presented with error 10334, which looks more ...
1
vote
1answer
233 views

CLR Assemblies and SQL Server Availability Groups

I have a SQL 2012 Availability group. On that I also have a database with a .Net assembly that is using PERMISSION_SET = UNSAFE. CREATE ASSEMBLY drawing FROM ...
1
vote
1answer
95 views

SQL CLR very slow on Amazon EC2 Instance (SQL Server 2014 CU6)

I am running a SQL Server 2014 Standard Edition (Cumulative Updates 6) instance on an r3.large Amazon EC2 box. I noticed that the CPU usage of SQL Server skyrockets to 100% while executing pretty much ...
1
vote
1answer
29 views

Is it possible to run an .exe file from a CLR function?

Is it possible to run an .exe from CLR function with Sybase SQL Anywhere 12? If yes then I thought about link this function and .exe with pipes, is it a good idea or do you have better ideas? If not ...
1
vote
0answers
42 views

How to use bcp utility in a CLR procedure as a process

I made an CLR Stored Procedure and I want to call bcp utility as a process in it. My project looks like : [SqlProcedure] public static int CmdShellBridgeBCP(string arguments) { return ...
1
vote
1answer
190 views

SQL Server to XML files alternatives

I am currently looking for an alternative to writing a large, complex XML file based on a known specification. Currently the file is written in t-sql as a stored procedure. The output is in a results ...
1
vote
0answers
20 views

CLR UDT SCH-M blocking

I’m hoping someone can provide some guidance on a problem I’m having with schema locking on C# CLR UDT’s. I’ve been on the Internet for an extended period of time researching my problem without ...