sqlclr

How does one use TimeZoneInfo in a SQLCLR assembly in SQL Server 2012

半世苍凉 提交于 2019-12-18 06:53:32
问题 I want to implement time zone conversion within SQL Server 2012. However, TimeZoneInfo is marked with the MayLeakOnAbort attribute. This causes a runtime error when the SQL function I defined (which uses TimeZoneInfo) is invoked. The error is reported as follows 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: MayLeakOnAbort

Can you create a CLR UDT to allow for a shared Table type across databases?

自闭症网瘾萝莉.ら 提交于 2019-12-18 04:24:18
问题 If I had a SQL statement such as this: CREATE TYPE [dbo].[typeRateLimitVariables] AS TABLE( [vchColumnName] [varchar](250) NULL, [decColumnValue] [decimal](25, 10) NULL ) And I used it as a table variable to a UDF in a database, I'd have sufficient scope. BUt let's say I wanted to call the scalar UDF from another database on the same server, then I'd end up with an unknown type error. I've tried creating the type on the calling DB, but obv. then I get a type mismatch because although each of

Multithreaded caching in SQL CLR

匆匆过客 提交于 2019-12-17 22:26:06
问题 Are there any multithreaded caching mechanisms that will work in a SQL CLR function without requiring the assembly to be registered as "unsafe"? As also described in this post, simply using a lock statement will throw an exception on a safe assembly: 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 I

SQL Server stops loading assembly

。_饼干妹妹 提交于 2019-12-17 21:58:59
问题 We have developed an assembly for SQL Server 2008 R2. The assembly has been working for a week. The managed stored proc inside the assembly was working fine for the whole week and then it stops working. We have been seeing this problem couple times. The way to make it work again is to restart the SQL Server. Msg 10314, Level 16, State 11, Line 4 An error occurred in the Microsoft .NET Framework while trying to load assembly id 65536. The server may be running out of resources, or the assembly

SQL Server 2008: How crash-safe is a CLR Stored Procedure that loads unmanaged libraries

坚强是说给别人听的谎言 提交于 2019-12-17 20:39:04
问题 We've got a regular (i.e. not extended) stored procedure in SQL Server 2000 that calls an external exe. That exe, in turn, loads a .dll that came from an SDK and calls some procedures from it (i.e. Init, DoStuff, Shutdown). The only reason we have this external exe thing is because we didn't want to create an extended stored procedure that would call the .dll. We believed that if the dll crashes (an unlikely event but still) then the SQL Server process will crash as well which is not what we

Register CLR function (WCF based) in SQL Server 2012

≡放荡痞女 提交于 2019-12-17 16:57:36
问题 I have a CLR based stored procedure which used MsmqIntegrationBinding to post messages to remote MSMQ's. Everything was working fine in SQL Server 2005 but now there is an upgrade from 2005 to 2012 suppose to happen. I tried to register the CLR (SP) in SQL Server 2012 but while registering System.ServiceModell.DLL it came up with the following error. Msg 6544, Level 16, State 1, Line 1 CREATE ASSEMBLY for assembly 'System.ServiceModel' failed because assembly 'microsoft.visualbasic.activities

How to make SqlContext.Pipe.Send in SQLCLR stored proc work with unicode?

…衆ロ難τιáo~ 提交于 2019-12-13 19:19:36
问题 I'm having problems with SQL CLR integration with unicode (Hebrew and Russian text). As a test, I made a simple database project in Visual Studio with the following CLR stored procedure: [Microsoft.SqlServer.Server.SqlProcedure] public static void TestProc () { //Console.OutputEncoding = System.Text.Encoding.Unicode; Trace.WriteLine("Unicode test: blip"); Trace.WriteLine("Unicode test: בליפ"); Trace.WriteLine("Unicode test: Блип"); SqlContext.Pipe.Send("Unicode test: blip"); SqlContext.Pipe

SQL CLR Function to replace TRY_CONVERT

牧云@^-^@ 提交于 2019-12-13 19:16:05
问题 I am trying to write my own CLR function to replace the built in 'TRY_CONVERT' sql function as I need more control over how dates and numbers are converted (e.g. the built-in function can't handle DECIMAL conversions that contain scientific notation). I have tried this: [SqlFunction(IsDeterministic = true, IsPrecise = true)] public static object TRY_CONVERT(SqlDbType type, SqlString input) { switch (type) { case SqlDbType.Decimal: decimal decimalOutput; return decimal.TryParse(input.Value,

How can I get a SQL String's collation within a CLR function?

白昼怎懂夜的黑 提交于 2019-12-13 18:30:48
问题 I'm writing a Levenshtein Distance function in C# to calculate the edit distance between two strings. The problem is that I'd like to call the method multiple times with different collations but only one collation ever makes it across the SQL to CLR interface - and that is the default collation of the database. Here is the code for the CLR Function: [SqlFunction(IsDeterministic = true, Name = "LevenshteinDistance")] public static SqlInt64 Distance(SqlString textA, SqlString textB) { // get a

Accessing Sql FILESTREAM from within a CLR stored procedure

被刻印的时光 ゝ 提交于 2019-12-13 14:13:48
问题 I'm trying to access a Sql filestream from a CLR stored procedure. I've set up a very simple database with a single table which includes a filestream column. I can successfully read from the filestream using a simple console app. Here's some example code for the proc that fails: [SqlProcedure] public static void GetDataFromFileStream(string path, out int data) { using (var connection = new SqlConnection("context connection=true")) { connection.Open(); var transaction = connection