I have a complex algorithm written in C # as a CLR stored procedure. The procedure is not deterministic (it depends on the current time). The result of the procedure are two tables. I did not find a solution how to handle multi-results from stored procedures in T-SQL. The execution of this procedure is key (the procedure is called every ~ 2 seconds).
I found the fastest way to update tables:
UPDATE [db-table] SET ... SELECT * FROM [clr-func]
This is much faster than updating the db table from the CLR procedure through ADO.NET.
I used a static field to store the results and query after executing the clr stored procedure.
Call stack:
T-SQL proc -> CLR proc (MyStoredProcedure) -> T-SQL proc (UpdateDataFromMyStoredProcedure) -> CLR func (GetFirstResultOfMyStoredProcedure) -> CLR func (GetSecondResultOfMyStoredProcedure)
The problem is that sometimes CLR functions have a null value in the static field result , but in the CLR procedure, result not null. I found that sometimes the CLR functions are called in a different AppDomain procedure than the CLR. However, the CLR procedure still works and can perform the following operations, and no exception is thrown.
Is there any way how to make the CLR functions invoked in the same AppDomain as the "parent" CLR procedure?
Or is there some other way to achieve my intention?
PS: Initially, a complex algorithm was written in T-SQL, but the performance was poor (~ 100 times slower than the algorithm in C #).
Thanks!
Simplified code:
// T-SQL CREATE PROC [dbo].[UpdateDataFromMyStoredProcedure] AS BEGIN UPDATE [dbo].[tblObject] SET ... SELECT * FROM [dbo].[GetFirstResultOfMyStoredProcedure]() UPDATE [dbo].[tblObjectAction] SET ... SELECT * FROM [dbo].[GetSecondResultOfMyStoredProcedure]() END // ... somewhere else EXEC [dbo].[MyStoredProcedure]
-
// C
source share