Examples

Current Articles | Categories | Search

Using a CLR TVF to SELECT Job Execution Status
By Jonathan Kehayias @ 6:57 PM :: 2742 Views :: 0 Comments

Trying to determine the status of a job in TSQL can be difficult if you are trying to do it through automated code.  You can't use a tempory table to store the results of sp_help_job since it already does this, and nested inserts of executing procedures is not allowed.  To get around this limitation, you can use a CLR TVF to return the output of sp_help_job as a table.

Read More..
Using a CLR TVF to SELECT from the SQL Error Log
By Jonathan Kehayias @ 6:39 PM :: 1475 Views :: 0 Comments

Monitoring ErrorLogs in SQL Server can be done a number of ways, but if you want to scan the contents in SQL and use filters to SELECT specific events from the Error Log in TSQL, it has traditionally required creating a temporary table to hold the results of xp_readerrorlog and then running your selects against this temp table.  This method requires a lot of code, and isn't a fast way to pull data on the fly.  Now with SQL CLR and Table Valued Functions it is simple to create a permanent solution to this problem.

Read More..
Parse hyperlinks from a file
By David Dye @ 8:09 AM :: 781 Views :: 0 Comments

One of the requirements of a project we implemented was to parse all the hyperlinks from documents and insert them into a table.  This clr stored procedure uses regex to parse all hyperlinks and insert each into into a table and column specified in the procedure.  Since the procedure accesses the file system it is necessary to set the permission to External.  There is extra code that I used to debug sending the statements to the message tab.  There are comments in these areas, but I left them in to make it easier to become familiar with the code and change as needed.

 

Read More..
Export xml query results to file
By David Dye @ 8:24 AM :: 1996 Views :: 3 Comments

This clr procedure accepts a file path and a FOR XML query and saves the xml results to the specified file.

Read More..
Write to event log
By David Dye @ 5:58 AM :: 1337 Views :: 0 Comments

The following example uses the clr to write to the event log.

Read More..
Previous Page | Next Page

Survey

Which of the following CLR objects are you currently using in SQL Server?




Submit Survey  View Results

Links

  Search

What's New

 Subscribe in a reader

Q&A with Adam Machanic - Who's Afraid of SQLCLR by Jonathan Kehayias

You could almost hear the gasps of horror when Microsoft integrated the .NET Common Language Runtime (CLR) into SQL Server 2005. Run C# or VB.NET code inside SQL Server? For many database developers and administrators, it was like an alien had just burst through SQL Server’s midsection.

But SQL Server MVP Adam Machanic says that more and more developers and DBAs are discovering that far from destroying SQL Server performance and security, SQLCLR is actually a powerful ally in solving complex business and technical problems.

Read More on the PASS website..

SQLCLR String Splitting Part 2: Even Faster, Even More Scalable by Site Administrator

SQL Server MVP Adam Machanic shows a new way of parsing strings in SQL Server using SQLCLR that outperforms all conventional TSQL methods, as well as the most common SQLCLR implemenations, using a custom split function that allows streaming of the results.

Trading in xp_cmdshell for SQLCLR (Part 1) - List Directory Contents by Jonathan Kehayias

Learn how to use SQLCLR to get file system information instead of using xp_cmdshell on your SQL Servers.

Recent Examples


Copyright 2007 by SQLCLR.net Terms Of Use Privacy Statement
Website graphics provided by Matt Green Designs
Page generated in 0.312002 seconds.

All information and example code on this site is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from its use.

This site is in no way affiliated with Microsoft. Unless specifically stated otherwise, nothing should be construed to represent the official positions or opinions of Microsoft and/or its Employees.