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:
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.
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.
Forgot to mention that we are using Umbraco version 4.7.2
is working on a reply...