Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6210879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:14:23+00:00 2026-05-24T06:14:23+00:00

I am getting the error Exception occurred in NLog —> System.Data.SqlClient.SqlException: Conversion failed when

  • 0

I am getting the error

Exception occurred in NLog ---> System.Data.SqlClient.SqlException: Conversion failed when converting from a character string to uniqueidentifier.

when I try to insert a NULL in the UserId column of the table which can take NULLS.

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      throwExceptions="true" internalLogFile="C:\Development\Projects\Pearson\ARIES\Development\Websites\ARIES.Web\NLog.log" internalLogLevel="Debug" >

    <!-- make sure to set 'Copy To Output Directory' option for this file -->
    <!-- go to http://nlog-project.org/wiki/Configuration_file for more information -->

    <targets>
        <target xsi:type="AsyncWrapper" queueLimit="2000" overflowAction="Grow" name="AsyncWrapperLogger" batchSize="1000">
            <target xsi:type="Database"
                    name="Database"
                    connectionStringName="ApplicationServices">
                <commandText>
                    insert into Logs(UserId, Level, Message, Exception, StackTrace, DateCreated) values(CASE WHEN @UserId IS NOT NULL AND @UserId = CAST('00000000-0000-0000-0000-000000000000' AS uniqueidentifier) THEN @UserId ELSE @UserId END, @Level, @Message, @Exception, @StackTrace, @DateCreated);
                </commandText>
                <parameter name="@UserId" layout="${event-context:item=${guid:format=UserId}}"/>
                <parameter name="@Level" layout="${level}"/>
                <parameter name="@Message" layout="${message}"/>
                <parameter name="@Exception" layout="${exception}"/>
                <parameter name="@StackTrace" layout="${stacktrace}"/>
                <parameter name="@DateCreated" layout="${date}"/>
            </target>
        </target>
    </targets>

    <rules>
        <logger name="*" writeTo="Database"/>
    </rules>
</nlog>

public static void Write(string message, Exception ex)
        {
            var logEventInfo = new LogEventInfo(NLog.LogLevel.Error, "", message);

            if (HttpContext.Current != null)
            {
                logEventInfo.Properties.Add("UserId", Guid.NewGuid());
            }

            logEventInfo.Exception = ex;

            logger.Log(logEventInfo);
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:14:23+00:00Added an answer on May 24, 2026 at 6:14 am

    Fixed it by using SQL Profiler. It was sending an empty string for the null GUID.

    insert into Logs(UserId, Level, Message, Exception, StackTrace, DateCreated) values(CASE WHEN @UserId = '' THEN NULL ELSE convert(uniqueidentifier, @UserId) END, @Level, @Message, @Exception, @StackTrace, @DateCreated);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this error: An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
I am getting a Method not found: 'Boolean MyCompany.LibraryAssembly.SomeFunction(System.String)' exception/error when running a VB.NET
Why am I getting this: An error occurred Application error Exception information: Message: Select
I am getting the error Format Exception was unhandled at Do While objectReader.Peek <>
Am getting following error message on calling WCF service: The formatter threw an exception
i'm getting exception on Transformer transformer = tFactory.newTransformer(StreamXSL); but the error below is not
in my application I am getting an exception: MyApp(38431,0xa004ffa0) malloc: *** error for object
In my web application i am using video conversion, i am getting error like
I am getting following error. Restore failed for Server I have recently upgraded SQL
I want to obtain all the replaced values in the following exception from error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.