sqlclr

Can't attach to SQL Server to debug SQLCLR Stored Procedure

ぃ、小莉子 提交于 2019-12-07 12:43:12
问题 I want to debug a SQLCLR stored procedure in SQL Server. I have been trying to debug an SP in VS2015 Community and in the recently installed VS2017 Community editions without success. I am pretty sure that the problem lies in attaching to SQL Server but as I've done everything I can find mentioned online but to no avail. When creating the database project in SQL Server Express LocalDB everything works fine. If I change the connection string to use my Developer Edition SQL Server, I then get

Can't add System.IO.Compression to trusted assemblies in SQL Server

早过忘川 提交于 2019-12-07 07:03:12
问题 I am trying to create a SQLCLR stored procedure in NET 4.5 that fiddles with ZIP files. Obviously System.IO.Compression is not on SQL Server's approved list but this is what I get when I try to add it manually via SQL Server Management Studio. The same happens if I try to execute CREATE ASSEMBLY via a query. Any ideas? Why is this a no-no? I have also tried running this command in SSMS: CREATE ASSEMBLY SystemIOCOMPRESSION FROM 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\

Accessing TSQL created #temp tables from CLR stored procedure. Is it possible?

为君一笑 提交于 2019-12-07 06:33:25
问题 I have a TSQL Stored Procedure tsql__sp__A which does two things: (a) Creates a temp table #tempTable that has SELECT data from a complex SELECT query. (b) Calls a CLR managed Stored Procedure clr__sp__B for each row that does computation on row parameters. Question: Is it possible to access #tempTable from CLR procedure clr__sp__B using the same connection context? (No, I don't want to move or create another #tempTable inside managed procedure) Thanks. 回答1: Thank you Boj. However I found

How to have a sql_variant parameter for a SQL CLR stored procedure?

为君一笑 提交于 2019-12-07 06:04:19
问题 How can one add a sql_variant parameter to a SQL CLR stored procedure? Using System.Object does not work, and I don't see any attributes that I can use. [Microsoft.SqlServer.Server.SqlProcedure] public static void ClearOnePartition( SqlString aString , /* I want this to be a sql_variant */ object aVariant ) { //do stuff here } 回答1: In Mapping CLR Parameter Data from SQL Books Online, Object is listed as the correct type to use to map sql_variant. I created a simple SQL Server project and

DRY CLR table-valued functions

隐身守侯 提交于 2019-12-07 04:56:38
问题 I'm using a CLR table-valued function to SELECT and return the results of a complex database search which uses many variables. The documentation shows that you build such a function in a fashion similar to this: public partial class UserDefinedFunctions { private class ResultRow // This class holds a row which we want to return. { public SqlInt32 CustId; public SqlString Name; public ResultRow(SqlInt32 custId_, SqlString name_) { CustId = custId_; Name = name_; } } [SqlFunction( DataAccess =

Is it safe to change static readonly variables in C# SQLCLR?

青春壹個敷衍的年華 提交于 2019-12-06 23:47:23
问题 I wrote some code in C# 6.0 .NET 3.5 CLR assembly with safety level = external_access . Reduced code: public static readonly DataTable warnings_table = init_warnings_table(); public static void set_warning(string msg) { var row = warnings_table.NewRow(); row[1] = DateTime.Now; row[2] = msg; ... warnings_table.Rows.Add(row); } [Microsoft.SqlServer.Server.SqlProcedure] public static SqlInt32 wrapper_func(SqlInt32 param) { return big_func(Param.Value); } int big_func(int param) { SqlBulkCopy

Performance and usage of CLR functions in SQL

北战南征 提交于 2019-12-06 12:42:25
SQL Server allows you to create CLR functions, stored procedures, user types and other objects, for purpose that are really complex to be done inside SQL. But, can someone compare those two things: TSQL Object and CLR Object, in sense of performance, benefits, and so on. What are real situations for usage CLR objects? Is there any best practices proposition for their usage? What are real situations for usage CLR objects? SQL Server lacks an aggregate string concatenation function. This bizarre oversight leads to all manner of complicated work-arounds. Creating and using a custom CLR aggregate

Best way to handle connection when calling a function from a Console App or SQLCLR object with (“Context Connection=true”)

北慕城南 提交于 2019-12-06 12:13:28
I have the following type of code in my data layer, which can be called from a console app, windows app, etc, with the proper connection string being read from the corresponding caller's App.Config file: public static udsDataset GetDataset(int datasetID) { string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; string sql = @"select * from Dataset WHERE DatasetID=@datasetID"; using (SqlConnection conn = new SqlConnection(connectionString)) { // Dapper query: return conn.Query<udsDataset>(sql, new {datasetID } ).First(); } } I now want to call this

Cannot register stdole assembly in SQL Server 2012

删除回忆录丶 提交于 2019-12-06 10:51:13
I am in the process of migrating a SQL Server 2008 to 2012 and running into challenges in creating some of the necessary assemblies for a CLR routine. The routine takes a dependency on stdole.dll , but I am unable to create this assembly. My code is as follows: ALTER DATABASE main SET TRUSTWORTHY ON; create assembly [stdole] from 'C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\stdole.dll' WITH PERMISSION_SET = unsafe I am receiving the following error: Warning: The Microsoft .NET Framework assembly 'stdole, version=7.0.3300.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.'

SqlDecimal issues in SQLCLR project

廉价感情. 提交于 2019-12-06 10:03:10
问题 I'm having some unexpected results when working with SqlDecimals. In the end it seems to boil down to scale issues when dividing 2 SqlDecimals. c# example code looks like this : [Microsoft.SqlServer.Server.SqlFunction] [return: SqlFacet(Precision = 38, Scale = 8)] public static SqlDecimal fn_divide([SqlFacet(Precision = 38, Scale = 8)]SqlDecimal x, [SqlFacet(Precision = 38, Scale = 8)]SqlDecimal y) { var r = SqlDecimal.Divide(@x, @y); return r; } SQL test code looks like this : DECLARE @x