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 12»»

Stairway to SQLCLR Level 1: What is SQLCLR? Expand / Collapse
Author
Message
Posted Tuesday, January 7, 2014 5:50 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 6:36 PM
Points: 370, Visits: 1,970
Comments posted to this topic are about the item Stairway to SQLCLR Level 1: What is SQLCLR?




SQL# - http://www.SQLsharp.com/
Post #1528722
Posted Thursday, January 9, 2014 6:25 AM


SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 5, 2014 12:21 PM
Points: 78, Visits: 193
Very timely for me. Another programmer deployed a CLR function about a year ago and I don't know anything about it. I've been saying I was going to learn C#, but have been remiss. I need to catch up, so I'm looking forward to the follow-up articles. Thanx!







Wallace Houston
Sunnyland Farms, Inc.

"We must endeavor to persevere."
Post #1529311
Posted Thursday, January 9, 2014 8:56 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 10:03 AM
Points: 1,895, Visits: 2,194
Looking forward to more steps. I need to do an EDI import routine, and think a CLR will fit he bill. Thanks!

Please don't go. The drones need you. They look up to you.
Connect to me on LinkedIn
Post #1529393
Posted Thursday, January 9, 2014 9:34 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 2:52 PM
Points: 751, Visits: 335
I am glad to see a reasonable and balanced approach to the article. Well written!

John.
Post #1529417
Posted Thursday, January 9, 2014 11:10 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 6:36 PM
Points: 370, Visits: 1,970
Caruncles (1/9/2014)
Very timely for me. Another programmer deployed a CLR function about a year ago and I don't know anything about it. I've been saying I was going to learn C#, but have been remiss. I need to catch up, so I'm looking forward to the follow-up articles. Thanx!


Hi there. You are quite welcome.

I assume you have the source code for that CLR function? Also, just to be clear: the goal of this series is to show how to work with the CLR Integration of .Net within SQL Server, not to educate on the topic of C#. I would recommend doing what you can to learn C# in the meantime so that you will have a better understanding of what the function is doing outside the scope of SQL Server interaction and nuances.

Take care,
Solomon...





SQL# - http://www.SQLsharp.com/
Post #1529467
Posted Thursday, January 9, 2014 11:18 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 6:36 PM
Points: 370, Visits: 1,970
Thomas Abraham (1/9/2014)
Looking forward to more steps. I need to do an EDI import routine, and think a CLR will fit he bill. Thanks!


You're welcome!

And just FYI, it will be a few more levels before we get to the specifics of creating Functions and Stored Procedures. There is a little more foundational content to go over first. But, by the time we get to those two levels I think you will have a good grasp of how to accomplish that project (assuming, of course, you know how to get the EDI data ).

Take care,
Solomon...





SQL# - http://www.SQLsharp.com/
Post #1529472
Posted Thursday, January 9, 2014 11:18 AM


SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 5, 2014 12:21 PM
Points: 78, Visits: 193
Yes, I have the source code and am aware that learning C# is not the focus of this topic. I've needed the C# to begin re-writes of custom VB6 programs which I'm finding won't run on 64-bit Windows 7 boxes. So, yes, I need to learn both, but your article is a good motivator for me. Thanx!







Wallace Houston
Sunnyland Farms, Inc.

"We must endeavor to persevere."
Post #1529473
Posted Thursday, January 9, 2014 11:19 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 6:36 PM
Points: 370, Visits: 1,970
Thomas Abraham (1/9/2014)
Looking forward to more steps. I need to do an EDI import routine, and think a CLR will fit he bill. Thanks!


Thank you (on all 3 counts)!

Take care,
Solomon...





SQL# - http://www.SQLsharp.com/
Post #1529475
Posted Thursday, January 9, 2014 11:23 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 6:36 PM
Points: 370, Visits: 1,970
Caruncles (1/9/2014)
Yes, I have the source code and am aware that learning C# is not the focus of this topic. I've needed the C# to begin re-writes of custom VB6 programs which I'm finding won't run on 64-bit Windows 7 boxes. So, yes, I need to learn both, but your article is a good motivator for me. Thanx!


No problem. I just needed to make sure so there was no potential for misunderstanding.

Good luck on learning C# and helping to remove VB6 from the planet .

Take care,
Solomon..





SQL# - http://www.SQLsharp.com/
Post #1529477
Posted Thursday, January 9, 2014 11:33 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, November 14, 2014 1:20 PM
Points: 7, Visits: 72
Great Article. I have been writing SQL Server external objects since 2007 and I have developed some best practices that work for me. You talked on most of them and I wanted to elaborate at bit on one of them.

Do as much of the operation in T-SQL that you can and write small external objects (SQLCLR tasks) to perform the tasks that cannot be done in T-SQL. In my experience, if a task could be done in T-SQL, it will always perform faster than in an external object. I have to admit that the article talked about some scenarios that I have not encounter yet, so testing is still the best way to truly know which has better performance.

Many moons ago I had a project to expose data in an external non-relational proprietary database within SQL Server so DBAs could perform aggregations on this data and also create reports on it , along with many other benefits of having the data in SQL Server (like BI).

Because the proprietary database had a COM SDK, I first tried using the sp_OA procedures. The T-SQL sp_OA procedures (OA stands for OLE Automation) allow SQL Server to run methods in a COM object. This method works for calls that have parameters with data types that map to SQL Server data types, like INTEGER and STRING, but not methods with parameters that do not, like ARRAY and OBJECT. This method did not work for me because the COM object used the data type of OBJECT to pass dates in.

Because I was using SQL Server 2005 I could perform the operation using the SQLCLR. I wrote an operation to connect to the external non-relational proprietary database and get the required data all via the SDK. I wrote the whole operation as one external stored procedure. I was floored when the execution took over 30 minutes to run. After investigating the cause, I discovered that SQL Server did some pre-process tasks that took about 30 minutes to run and the actual tasks I wrote took 3 seconds. Further investigation lead me to believe that SQL Server tries to understand what is required if a rollback is called. I then changed the architecture of the operation to have multiple small SQLCLR tasks with one T-SQL to call them, process the data and then return the results. With this architecture, the tasks run in 3 seconds.

I hope my trial and errors help someone.
Post #1529484
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse