sqlclr

SqlFunction fails to open context connection despite DataAccessKind.Read present

て烟熏妆下的殇ゞ 提交于 2019-11-30 23:25:58
问题 I've got a SqlServer project with a very simple test for a Table-Valued-Function:- [SqlFunction(TableDefinition = "forename nvarchar(50)", FillRowMethodName = "TestFillRow", DataAccess = DataAccessKind.Read)] public static IEnumerable TestConn(int ID) { using (SqlConnection con = new SqlConnection("context connection=true")) { //con.Open(); yield return "Anthony"; } } public static void TestFillRow(object obj, out string forename) { forename = (string)obj; } Note the Open on the connection is

SQL Server CLR UDF Parallelism redux

◇◆丶佛笑我妖孽 提交于 2019-11-30 23:14:48
I have been researching SQL Server CLR UDFs and parallelism for some time. The general consensus seems to be that in SQL Server 2008 and later, a scalar value CLR UDF with DataAccessKind.None should allow parallel execution. However, when I use my scalar value UDF in my view in SQL Server 2012, it still kills parallel execution in joins and the like. Is there something special I need to add to my C# code or the T-SQL UDF definition to indicate that it is safe for parallel execution? Thanks. According to the MSDN forum that is linked to in the first comment on the question, your C# code roughly

Synchronize access to static variables in sql server SQLCLR

半腔热情 提交于 2019-11-30 21:58:09
I have written an assembly which is integrated in sql server, providing some stored procedures written in C#. The assembly has a readonly static variable holding some configuration data. This data is manipulated via stored procedures, which are also provided by the assembly. Obviously I have to synchronize access to this static variable. I tried to use lock(someGuard) { // ... access static configuration } inside my configuration class. But then I get a HostProtectionException, telling me, that the assembly has to run with full trust to do that. Is there a better way to do that? There is

Security risks of setting trustworthy = on in sql server 2012

主宰稳场 提交于 2019-11-30 20:06:36
I get the following errors in my development database: A .NET Framework error occurred during execution of user-defined routine or aggregate "SpCreateTable": System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host. The protected resources (only available with full trust) were: All The demanded resources were: Synchronization, ExternalThreading Is the correct solution to set trustworthy = on? What are security concerns with this? The TRUSTWORTHY property of a database (when set to ON ) essentially declares to SQL Server that code contained

Is it possible to create an asymmetric key for a .NET framework assembly in SQL Server 2014?

梦想的初衷 提交于 2019-11-30 18:47:26
I am developping an SQL Server Database Project in Visual Studio which is in fact a User Defined Function. In this project, I included Json.NET as a reference (using NuGet). I managed to publish (and make work) my assembly and the UDF to my SQL Server instance by first turning the database TRUSTWORTHY ON (since my project is UNSAFE) and then running this: CREATE ASSEMBLY [System.Runtime.Serialization] FROM 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.Serialization.dll' WITH PERMISSION_SET = UNSAFE; Which turns out to be an assembly Json.NET depends on (if I don't do it, I get

Synchronize access to static variables in sql server SQLCLR

╄→尐↘猪︶ㄣ 提交于 2019-11-30 17:50:55
问题 I have written an assembly which is integrated in sql server, providing some stored procedures written in C#. The assembly has a readonly static variable holding some configuration data. This data is manipulated via stored procedures, which are also provided by the assembly. Obviously I have to synchronize access to this static variable. I tried to use lock(someGuard) { // ... access static configuration } inside my configuration class. But then I get a HostProtectionException, telling me,

SQL Server CLR Threading

你。 提交于 2019-11-30 15:20:55
问题 I have been struggling with a SQL Server CLR stored procedure. Background: We are using SQL Server 2014 and a CLR stored procedure has been implemented which calls a customer's web service. The threading was initially used not to slow the main thread of SQL Server CLR. Although, now, I know that using threading under CLR is no best idea, it has been working correctly for 6 years (since SQL Server 2008). It has been migrated to SQL Server 2014 recently. The problem On my development machine,

SQL Server CLR Threading

你离开我真会死。 提交于 2019-11-30 13:49:33
I have been struggling with a SQL Server CLR stored procedure. Background: We are using SQL Server 2014 and a CLR stored procedure has been implemented which calls a customer's web service. The threading was initially used not to slow the main thread of SQL Server CLR. Although, now, I know that using threading under CLR is no best idea, it has been working correctly for 6 years (since SQL Server 2008). It has been migrated to SQL Server 2014 recently. The problem On my development machine, same as on test system we have no problem with the solution. On the customer system, the thread, which

Failed to CREATE AN ASSEMBLY in SQL

萝らか妹 提交于 2019-11-30 11:05:35
I've already dived into SQL clr programming. Unfortunately my first attempt is troubled. My C# assembly code is just so: enter code here public partial class FirstCLRRoutines { public static int GetCLRFrameworkMajorVersion() { return System.Environment.Version.Major; } } And SQL code is: USE master GO CREATE ASSEMBLY [Chapter2.FirstCLRRoutine] FROM 'D:\projeler\SQL_CLR\SQL_CLR\bin\Debug\SQL_CLR.dll' But I get this error message from MSSMSE: Msg 6218, Level 16, State 3, Line 1 CREATE ASSEMBLY for assembly 'SQL_CLR' failed because assembly 'SQL_CLR' failed verification. Check if the referenced

Can SQL CLR triggers do this? Or is there a better way?

*爱你&永不变心* 提交于 2019-11-30 09:02:13
问题 I want to write a service (probably in c#) that monitors a database table. When a record is inserted into the table I want the service to grab the newly inserted data, and perform some complex business logic with it (too complex for TSQL). One option is to have the service periodically check the table to see if new records have been inserted. The problem with doing it that way is that I want the service to know about the inserts as soon as they happen, and I don't want to kill the database