I'm using SqlHelper in my Umbraco Base methods to query this custom table I added to my database for custom information. This is my code :
var sqlHelper = umbraco.BusinessLogic.Application.SqlHelper;
var reader = sqlHelper.ExecuteReader(
"SELECT * " +
"FROM myCustomTable " +
"WHERE SomeId = @SomeId",
sqlHelper.CreateParameter("@SomeId", someIdFromMyCode)
);
if (reader.Read())
{
var someOtherId = reader.GetInt("SomeOtherId");
if (someOtherId > 0) {
// Do stuff
}
}
Ok so this works very well, my question is that I'm wondering how SqlHelper will manage DBConnection and ressources and when will it free up the memory and etc. I don't want this to be too heavy for my server, should I wrap this in a using or something else?
Since this is in base, this is called by Ajax-jquery so it can get it "often". What are the best practices around this SqlHelper. I tried looking in umbraco source but it's quite deep in there through factory patterns and stuff that I don't really want to read through.
Here is the answer. Umbraco's SqlHelper uses Microsoft.ApplicationBlocks.Data.SqlHelper which handles connection and ressouce management. So no need to worry about this. Found this in umbraco.datalayer/SqlHelpers/SqlServer/SqlServerHelper.cs:
using SH = Microsoft.ApplicationBlocks.Data.SqlHelper;
Using SqlHelper, freeing up ressources after use.
Hello,
I'm using SqlHelper in my Umbraco Base methods to query this custom table I added to my database for custom information. This is my code :
Ok so this works very well, my question is that I'm wondering how SqlHelper will manage DBConnection and ressources and when will it free up the memory and etc. I don't want this to be too heavy for my server, should I wrap this in a using or something else?
Since this is in base, this is called by Ajax-jquery so it can get it "often". What are the best practices around this SqlHelper. I tried looking in umbraco source but it's quite deep in there through factory patterns and stuff that I don't really want to read through.
Maybe someone here knows about this?
Thank you!
Sébastien
Here is the answer. Umbraco's SqlHelper uses Microsoft.ApplicationBlocks.Data.SqlHelper which handles connection and ressouce management. So no need to worry about this. Found this in umbraco.datalayer/SqlHelpers/SqlServer/SqlServerHelper.cs:
Cheers!
Seb
is working on a reply...