Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sébastien Richer 194 posts 430 karma points
    Dec 07, 2012 @ 16:06
    Sébastien Richer
    0

    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 :

    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.

    Maybe someone here knows about this?

    Thank you!

    Sébastien

     

  • Sébastien Richer 194 posts 430 karma points
    Dec 10, 2012 @ 17:48
    Sébastien Richer
    0

    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;

     

    Cheers!

    Seb

Please Sign in or register to post replies

Write your reply to:

Draft