Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««1234»»

CLR Integration Expand / Collapse
Author
Message
Posted Wednesday, July 20, 2005 3:34 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, January 31, 2014 7:46 AM
Points: 1,599, Visits: 134
I think the one thing missing in this discussion is that although when used for the correct purposes CLR integration will prove addition to sql server it still falls foul of the same performance hit that you get with xprocs.

This is because the UMS's in sql server works in a non-preemptive mode i.e. it is a co-operative scheduler and the functions to yield are not available to external applications that is if you could trust them to yield when they should so to schedule a CLR assembly sql passes the thread to to the windows scheduler so that it can be scheduled pre-emptively and then starts up a new thread to handle the work of the sscheduler object from which the thread was taken.

This all involves context and keranl switching it's even worse if it then needs to acces the oDS layer as this involves more context switching etc.

Regards


David
Post #202918
Posted Wednesday, July 27, 2005 7:11 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 6:46 PM
Points: 1,113, Visits: 704
David --

Although SQL Server 2005 still schedules preemtively, UMS is gone (see: http://blogs.msdn.com/slavao/archive/2005/02/05/367816.aspx ). I believe SQLOS is supposed to handle context switching and other problems a lot more elegantly than UMS.


--
Adam Machanic
SQL Server MVP
SQLblog.com: THE SQL Server Blog Spot on the Web
Post #205151
Posted Thursday, July 28, 2005 12:44 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, January 31, 2014 7:46 AM
Points: 1,599, Visits: 134
My understanding from Ken Henderson's blog and is that this will still be an issue in 2005 but by the sound of slava's blog maybe not as bad hmm looks like we could be waiting on Ken's or Kalen's book on 2005 to clarify just what the performance issues are if any in using CLR for stored procs.

Anyway ta for the link it was an interesting read.
Post #205176
Posted Monday, September 26, 2005 2:27 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, August 5, 2014 1:35 PM
Points: 865, Visits: 872

I thought the article and example are quite interesting...but... what is the significance of " [Microsoft.SqlServer.Server.SqlFunction]" in

              public partial class UserDefinedFunctions
              {
               [Microsoft.SqlServer.Server.SqlFunction]

 

That, in summary, is a problem for me. I know sql better than .NET, be it VB.NET of C#.

 

Bill


 




Post #223732
Posted Monday, September 26, 2005 3:39 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 6:46 PM
Points: 1,113, Visits: 704
SqlFunctionAttribute is an attribute that marks a method as a function -- so that SQL Server knows how you intend to use the method.

For more information on attributes, see:

http://insight.zdnet.co.uk/software/applications/0,39020466,2118655,00.htm


--
Adam Machanic
SQL Server MVP
SQLblog.com: THE SQL Server Blog Spot on the Web
Post #223744
Posted Sunday, June 22, 2008 6:33 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Sunday, March 14, 2010 9:41 PM
Points: 56, Visits: 119
I realize that the Sql Server Project Template is only available in the Professional edition of VS but wouldn't it be possible to create a CLR proc by just creating a class library and somehow deploying it manually?

"What I lack in youth I make up for in immaturity!"
Please visit my music site at http://woundedego.com
Post #521400
Posted Sunday, June 22, 2008 8:07 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 6:46 PM
Points: 1,113, Visits: 704
billross (6/22/2008)
I realize that the Sql Server Project Template is only available in the Professional edition of VS but wouldn't it be possible to create a CLR proc by just creating a class library and somehow deploying it manually?


Absolutely. Compile your DLL, then use CREATE ASSEMBLY to register it with your database. Once you've done that you can use CREATE PROCEDURE, CREATE FUNCTION, etc, with the EXTERNAL NAME option to map your procedures, functions, etc, to the methods in the assembly.


--
Adam Machanic
SQL Server MVP
SQLblog.com: THE SQL Server Blog Spot on the Web
Post #521402
Posted Sunday, June 22, 2008 10:46 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Sunday, March 14, 2010 9:41 PM
Points: 56, Visits: 119
Thanks for the reply. I've been successful and for the benefit of others who want to do this, I illustrate your steps with an example from my application....

First, I enable CLR:

-- enable/disable the CLR
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
--sp_configure 'clr enabled', 0; -- disable
sp_configure 'clr enabled', 1; -- enable
GO
RECONFIGURE;
GO


>>>>Compile your DLL

Ok, this is my DLL:

CTSStoredProcs.cs
using System.Data.SqlTypes;
using System.Text.RegularExpressions;
using Microsoft.SqlServer.Server;

public partial class CTSStoredProcs
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlBoolean RegExValidate(
SqlString expressionToValidate, SqlString regularExpression)
{
Regex regex = new Regex(regularExpression.Value);

return regex.IsMatch(expressionToValidate.Value);
}
}

I got a clean build.

>>>then use CREATE ASSEMBLY to register it with your database.

Here is my Create Assembly script:

CREATE ASSEMBLY CTSWebStoredProcs
FROM 'C:\Projects\CTSWebClassLibrary\bin\Debug\CtsWebClassLibrary.dll'
WITH PERMISSION_SET = SAFE;
GO

This runs and I get an entry in my Assemblies of CTSWebStoredProcs.

>>>>Once you've done that you can use CREATE PROCEDURE, CREATE FUNCTION, etc, with the EXTERNAL NAME option to map your procedures, functions, etc, to the methods in the assembly.

Here is my CREATE FUNCTION:

CREATE FUNCTION dbo.RegExValidate
(@expressionToValidate nVarChar(100),
@regularExpressionparameter_name nVarChar(100))
RETURNS bit
EXTERNAL NAME CTSWebStoredProcs.CTSStoredProcs.RegExValidate

I now have an entry in my Scalar Functions of dbo.RegExValidate.

When I call the example, it validates perfectly:

DROP TABLE dbo.PEOPLE
GO
CREATE TABLE dbo.PEOPLE (
name VARCHAR(25) NOT NULL
, emailaddress VARCHAR(255) NOT NULL
, CONSTRAINT PEOPLE_ck_validemailaddress
CHECK ( dbo.RegExValidate( emailaddress, N'^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$' ) = 1 )
)
go

DECLARE @regex NVARCHAR(100)
SET @regex = N'^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$'
SELECT name, emailaddress, dbo.RegExValidate( emailaddress, @regex ) AS validemail FROM dbo.PEOPLE
go

Fantastic - thanks!


"What I lack in youth I make up for in immaturity!"
Please visit my music site at http://woundedego.com
Post #521429
Posted Sunday, June 22, 2008 10:54 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 6:46 PM
Points: 1,113, Visits: 704
Looks good, but you might want to apply the IsDeterministic and IsPrecise options on the SqlFunctionAttribute so that you can use your function in a wider variety of scenarios (such as a persisted computed column or an indexed view).



--
Adam Machanic
SQL Server MVP
SQLblog.com: THE SQL Server Blog Spot on the Web
Post #521430
Posted Sunday, June 22, 2008 11:16 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Sunday, March 14, 2010 9:41 PM
Points: 56, Visits: 119
Thanks. I wonder if you could show me how to do it. I tried this:

CREATE FUNCTION dbo.RegExValidate
(@expressionToValidate nVarChar(100),
@regularExpressionparameter_name nVarChar(100))
RETURNS bit
WITH IsDeterministic, IsPrecise
EXTERNAL NAME CTSWebStoredProcs.CTSStoredProcs.RegExValidate
GO

I didn't get squiggly lines, but when it ran it said that IsDeterministic is not a recognized option.


"What I lack in youth I make up for in immaturity!"
Please visit my music site at http://woundedego.com
Post #521432
« Prev Topic | Next Topic »

Add to briefcase «««1234»»

Permissions Expand / Collapse