Good morning!
May anybody tell me which is the best practice and why when I program inside a CLR stored procedure or CLR function or Other CLR?
I may have my code like this:
using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; namespace test { public class StoredProcedures { [Microsoft.SqlServer.Server.SqlProcedure] public static void test ( // Some parameters ) { // Some .Net code using (SqlConnection conn = new SqlConnection("context connection=true")) { //Some TSQL code } // Some .Net code using (SqlConnection conn = new SqlConnection("context connection=true")) { //Some TSQL code } // Some .Net code using (SqlConnection conn = new SqlConnection("context connection=true")) { //Some TSQL code } // Some .Net code } } }
Or I may have my code something like this:
using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; namespace test { public class StoredProcedures { [Microsoft.SqlServer.Server.SqlProcedure] public static void test ( // Some parameters ) { // Some .Net code using (SqlConnection conn = new SqlConnection("context connection=true")) { //Some TSQL code //Some .Net code //Some TSQL code //Some .Net code //Some TSQL code } // Some .Net code } } }
As you may see I may have several connections inside the CLR or I may have a single connection. Wich is the best practice and why?
Thanks a lot for your valuable help.
Regards,
Jamesit0