In short, is this a good design decision to implement most of the business logic in CLR stored procedures ?
I read a lot about them recently, but I canβt understand when they should be used, what are the best practices, are they good enough or not.
For example, my business application should
- parse a large text file with a fixed length,
- extract some numbers from each line in the file,
- according to these numbers, some complex business rules apply (including matching regular expressions, matching patterns with data from many tables in the database, etc.),
- and as a result of this calculation, the records in the database are updated.
There is also a graphical user interface for selecting a file, viewing results, etc.
This application seems to be a good candidate for implementing the classic three-tier architecture: data layer, logic level and GUI layer.
- Data tier will access the database
- Logic Layer will act as a WCF service and implement business rules by interacting with the data layer
- The GUI layer will be the means of communication between the logical layer and the user.
Now, having thought about this project, I see that most business rules can be implemented in the SQL CLR and stored in SQL Server. I could store all my source data in a database, start processing there and get the results. I see some advantages and disadvantages of this solution:
Pros
- Business logic is approaching data, which means less network traffic.
- Process all data at once, possibly using concurrency and an optimal execution plan.
against
- The scattering of business logic: some part is here, some part is.
- A dubious design decision may run into unknown problems.
- It is difficult to implement a progress indicator for a processing task.
I would like to hear all your opinions on SQL CLR. Does anyone use it in production? Are there any problems with this design? It's good?
Gart source share