sqlclr

Programatically read SQL Server's query plan suggested indexes for a specific execution of SQL?

删除回忆录丶 提交于 2019-12-03 15:08:00
If I run this command in SSMS: set showplan_xml on GO exec some_procedure 'arg1', 'arg2','arg3' GO set showplan_xml off GO I get XML output of the full call stack involved in the query execution, as well as any suggested indexes etc. How might one read this from C#? (One use case might be to periodically enable this and log these results in a production environment to keep an eye on index suggestions.) This is, for the most part, two separate (though related) questions. Is it possible to capture or somehow get the Missing Index information? If you want only the Suggested Indexes (and don't

CLR assembly will not load in 64 bit SQL Server 2005

家住魔仙堡 提交于 2019-12-03 14:48:39
We use an assembly with some user defined functions in our installation of SQL Server 2005 (32 bit). We deploy this to production with a script like this: CREATE ASSEMBLY [Ourfunctions] AUTHORIZATION [dbo] FROM 0x4D5A9000...000 WITH PERMISSION_SET = SAFE GO CREATE FUNCTION [dbo].[GLOBAL_FormatString](@input [nvarchar](4000)) RETURNS [nvarchar](4000) WITH EXECUTE AS CALLER AS EXTERNAL NAME [Ourfunctions].[UserDefinedFunctions].[GLOBAL_FormatString] GO We have never experienced any problems with these functions. Now, when we tried to upgrade one of our servers to x64, we got errors when calling

Can the F# core libs be SQLCLR-approved?

≯℡__Kan透↙ 提交于 2019-12-03 13:27:34
According to this thread, F# Core must be SQLCLR-approved for assemblies to be marked SAFE . Is this planned? Can it even be done? I believe it can be done. However, F# core library is the sole property of Microsoft. This means you can't modify its code and recompile it to match and comply with SQLCLR SAFE. I suggest you add suggestion to Microsoft using Microsoft's connect website. Microsoft connect is at: http://connect.microsoft.com (you have to register and have email account on live.com or hotmail.com before register). To manually add your .NET DLL and integrate it to SQL Server, you can

SSDT SQL Server Debugging Doesn't Hit CLR Breakpoints

时光总嘲笑我的痴心妄想 提交于 2019-12-03 12:21:55
问题 I applied the SQL Server Data Tools patch to Visual Studio 2012 (Premium) and created a SQL Server CLR user-defined function project in C#: public partial class UserDefinedFunctions { [Microsoft.SqlServer.Server.SqlFunction] public static SqlInt32 Add42(SqlInt32 in_param) { SqlInt32 retval = in_param + 42; // Set break point here. return retval; } } In the SQL Server Object Explorer pane, I right-click on the newly published UDF and select "Execute Function..." I am prompted to supply a

SQL CLR project in vs2012

自作多情 提交于 2019-12-03 11:27:19
问题 After installing the release version of VS2012, I am unable to find SQL CLR proect template. How can I go about creating a project of this type. Thanks! 回答1: All of the various database objects are now created inside of SQL Server database projects. They've removed the distinction between database projects (SQL Scripts) and SQL CLR projects. So it's just File -> New -> Project , Installed -> Templates -> SQL Server , SQL Server Database Project . Then, if you go to Add -> New Item , you'll

Code first Entity Framework 6.1 Custom Aggregate Function

我怕爱的太早我们不能终老 提交于 2019-12-03 08:46:31
I have a custom CLR Aggregate function on SQL Server to calculate percentiles. Is it possible to call my custom aggregate function through Entity Framework? How is the mapping configured to allow this? I have tried using codefirstfunctions similar to what is described on Entity Framework 6 Code First Custom Functions , however the functions seem to only be allowed to take scaler parameters, where my function is an aggregate function so will need to take a list of items (similar to how Sum, Averagg and Count work). The Aggregate functions has the following signature, taking in the value we want

SQL Server: How to list all CLR functions/procedures/objects for assembly

荒凉一梦 提交于 2019-12-03 05:34:39
问题 Question: In SQL Server 2005, how can I list all SQL CLR-functions/procedures that use assembly xy (e.g. MyFirstUdp) ? For example a function that lists HelloWorld for query parameter MyFirstUdp CREATE PROCEDURE HelloWorld AS EXTERNAL NAME MyFirstUdp.[SQL_CLRdll.MySQLclass].HelloWorld GO after I ran CREATE ASSEMBLY MyFirstUdp FROM 'C:\Users\username\Documents\Visual Studio 2005\Projects\SQL_CLRdll\SQL_CLRdll\bin\Debug\SQL_CLRdll.dll I can list all assemblies and all functions/procedures, but

HttpWebRequest runs slowly first time within SQLCLR

為{幸葍}努か 提交于 2019-12-03 03:41:27
When making an HttpWebRequest within a CLR stored procedure (as per the code below), the first invocation after the Sql Server is (re-)started or after a given (but indeterminate) period of time waits for quite a length of time on the GetResponse() method call. Is there any way to resolve this that doesn't involve a "hack" such as having a Sql Server Agent job running every few minutes to try and ensure that the first "slow" call is made by the Agent and not "real" production code? function SqlString MakeWebRequest(string address, string parameters, int connectTO) { SqlString returnData;

SSDT SQL Server Debugging Doesn't Hit CLR Breakpoints

China☆狼群 提交于 2019-12-03 02:49:17
I applied the SQL Server Data Tools patch to Visual Studio 2012 (Premium) and created a SQL Server CLR user-defined function project in C#: public partial class UserDefinedFunctions { [Microsoft.SqlServer.Server.SqlFunction] public static SqlInt32 Add42(SqlInt32 in_param) { SqlInt32 retval = in_param + 42; // Set break point here. return retval; } } In the SQL Server Object Explorer pane, I right-click on the newly published UDF and select "Execute Function..." I am prompted to supply a sample input value, and Visual Studio then publishes the function (again) to my local 2012 SQL Server and

SQL Server: Could not find type in the assembly

孤人 提交于 2019-12-03 02:37:02
问题 Assume the assembly dll: using Microsoft.SqlServer.Server; using System.Data.SqlClient; using System.Data.SqlTypes; using System; using System.Text; namespace CLRFunctions { public class T { [SqlFunction(DataAccess = DataAccessKind.Read)] public static String NormalizeString(String s, String normalizationForm) { NormalizationForm form = NormalizationForm.FormC; if (String.Equals(f, "FormD", StringComparison.OrdinalIgnoreCase)) form = NormalizationForm.FormD; return = s.Normalize(form); } } }