Copied to clipboard

Flag this post as spam?

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


  • Jason Evans 50 posts 71 karma points
    Aug 07, 2012 @ 11:23
    Jason Evans
    0

    Conversion failed when converting the nvarchar value 'Debug' to data type int. when calling Log.GetLogItems

    Hi there.

    I am using the Log class' method public List<LogItem> GetLogItems(User user, LogTypes type, DateTime sinceDate) method to retrieve log items and each time I execute this method I encounter the following error:

    “Conversion failed when converting the nvarchar value 'Debug' to data type int.”

    Looking closer I can see the problem, which is this line:

        SqlHelper.CreateParameter("@logHeader", type)

    Now "type" is a LogTypes enum value and what happens is that, in the SQL the value of the enum value, rather then it's name, is being passed to the SQL. So you end up with:

    WHERE logHeader = 13

    when it should be

    WHERE logHeader = 'Login'

    The fix is easy, you can do this:

        SqlHelper.CreateParameter("@logHeader", type.ToString())

    Explicitly calling ToString() results in the second WHERE clause ocurring, which is what we want. Howver, we naturally would prefer this to be included in the official Umbraco build rather then us deploying a custom version of the code.

    Many Thanks.

    Jason.

     

  • Jason Evans 50 posts 71 karma points
    Aug 07, 2012 @ 11:25
    Jason Evans
    0

    Forgot to mention that we are using Umbraco version 4.7.2

Please Sign in or register to post replies

Write your reply to:

Draft