Exception handling - DB logging failed coz of improper credentials

Topics: Data Access Application Block, Exception Handling Application Block, Logging Application Block
Jul 8, 2009 at 3:11 PM

I get the below exception when trying to log an exception into the DB using exception handling block and logging block.

I see that the error's inenr message says "Message: Login failed for user 'XYZ\CHNMCT90199$'." where XYZ is the domain name and CHNMCT90199$ is my machine name. Why is this passed as credential instead of my user name?

Timestamp: 7/8/2009 2:06:41 PM
Message: Tracing to LogSource 'DBLog Category' failed. Processing for other sources will continue. See summary information below for more information. Should this problem persist, stop the service and check the configuration file(s) for possible error(s) in the configuration of the categories and sinks.

Summary for Enterprise Library Distributor Service:
Timestamp: 7/8/2009 2:06:41 PM
Message: HandlingInstanceID: 5e97ed8c-ab6d-4b09-9839-743afa1c6ca6
An exception of type 'System.FormatException' occurred and was caught.
07/08/2009 19:36:41
Type : System.FormatException, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Input string was not in a correct format.
Source : Tomra.Enterprise.PS.BPC
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void StringToNumber(System.String, System.Globalization.NumberStyles, NumberBuffer ByRef, System.Globalization.NumberFormatInfo, Boolean)
Stack Trace :    at Tomra.Enterprise.PS.BPC.DistributorTransactionsBPC.GetDistributorList(EntityProtocol entityInput) in E:\Projects\MICHIGAN\SourceCode\PSWebApp\Tomra.Enterprise.PS.BPC\DistributorTransactionsBPC.cs:line 61
   at Tomra.Enterprise.PS.WCF.PSService.GetDistributorList(EntityProtocol entityInput) in E:\Projects\MICHIGAN\SourceCode\PSWebApp\Tomra.Enterprise.PS.WCF\PSService.svc.cs:line 256

Additional Info:

MachineName : CHNMCT90199
TimeStamp : 7/8/2009 2:06:41 PM
FullName : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
AppDomainName : /LM/w3svc/1/ROOT/PS_WCF-1-128915355919400811
ThreadIdentity : ITLINFOSYS\rajasoorya_kc
WindowsIdentity : ITLINFOSYS\rajasoorya_kc

Category: DBLog Category
Priority: 0
EventId: 100
Severity: Error
Title:Enterprise Library Exception Handling
Machine: CHNMCT90199
App Domain: /LM/w3svc/1/ROOT/PS_WCF-1-128915355919400811
ProcessId: 1344
Process Name: c:\windows\system32\inetsrv\w3wp.exe
Thread Name:
Win32 ThreadId:5104
Extended Properties: Category - Error
ExceptionID - 1
WrappedMessage - Application encountered an error
InnerMessage - Input string was not in a correct format.
Source - RequestAuthorizationDAO
Method - LoadDropDownForBarcodeAuthorization
TargetSite - Void StringToNumber(System.String, System.Globalization.NumberStyles, NumberBuffer ByRef, System.Globalization.NumberFormatInfo, Boolean)
StackTrace -    at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Convert.ToInt32(String value)
   at Tomra.Enterprise.PS.DAO.DistributorTransactionsDAO.GetDistributorList(EntityProtocol entityInput) in E:\Projects\MICHIGAN\SourceCode\PSWebApp\Tomra.Enterprise.PS.DAO\DistributorTransactionsDAO.cs:line 59
NameSpace -

--> MachineName: CHNMCT90199
--> TimeStamp: 7/8/2009 2:06:41 PM
--> FullName: Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
--> AppDomainName: /LM/w3svc/1/ROOT/PS_WCF-1-128915355919400811

Exception Information Details:
Exception Type: System.Data.SqlClient.SqlException
Errors: System.Data.SqlClient.SqlErrorCollection
Class: 14
LineNumber: 65536
Number: 18456
Server: chnmct113554
State: 1
Source: .Net SqlClient Data Provider
ErrorCode: -2146232060
Message: Login failed for user 'ITLINFOSYS\CHNMCT90199$'.
Data: System.Collections.ListDictionaryInternal
TargetSite: Void OnError(System.Data.SqlClient.SqlException, Boolean)
HelpLink: NULL

StackTrace Information Details:
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener.ExecuteStoredProcedure(LogEntry logEntry)
   at Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data)
   at Microsoft.Practices.EnterpriseLibrary.Logging.LogSource.TraceData(TraceEventType eventType, Int32 id, LogEntry logEntry, TraceListenerFilter traceListenerFilter)
   at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter.ProcessLog(LogEntry log)
Priority: -1
EventId: 6352
Severity: Error
Machine: CHNMCT90199
Application Domain: /LM/w3svc/1/ROOT/PS_WCF-1-128915355919400811
Process Id: 1344
Process Name: c:\windows\system32\inetsrv\w3wp.exe
Win32 Thread Id: 5104
Thread Name:
Extended Properties:

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Jul 8, 2009 at 3:22 PM

Is this an asp.net application?  Does your app allow impersonation?  It seems like it doesn't because it should've used your credentials. 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Jul 8, 2009 at 3:26 PM

Yes it is a web application. And the IIS has been configured to impersonate.

I am able to connect to the DB with the data access block for fetching the data from the DB using stored procs. I face this issue only when i am trying to log into the DB in case of an exception.

In fact, i am using the same connection for both, the stored proc call and the exception logging.

Jul 8, 2009 at 3:34 PM

Just to make sure, could you check your web.config for this tag, <identity impersonate="true" />?


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Jul 8, 2009 at 3:36 PM

Yes. I do have it in my web config

Jul 8, 2009 at 3:44 PM

Have you looked into this error - Login failed for user 'ITLINFOSYS\CHNMCT90199$'.  What is ITLINFOSYS?


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Jul 8, 2009 at 3:46 PM

ITLINFOSYS is my domain name.

It should have been ITLINFOSYS\rajasoorya_kc where rajasoorya_kc is my user id. Instead my machine name is passed.

Jul 8, 2009 at 4:03 PM

What does the code WindowsIdentity.GetCurrent().Name return in your app?


Jul 8, 2009 at 4:11 PM


Jul 8, 2009 at 4:21 PM

That's weird.  So the impersonation somehow stopped when the database tracelistener is trying to write to the database.  Are you using the out-of-the-box database tracelistener? Or you made some changes and rebuild the assembly? 

Jul 8, 2009 at 4:23 PM

I have NOT done any changes to the EL source code.

What is an out-of-the-box database tracelistener? I am jsut using the conventional database trace listener.

Jul 8, 2009 at 4:30 PM
Edited Jul 8, 2009 at 4:33 PM

That only points to the database tracelistener that is shipped with EntLib.  I honestly don't have an idea why would it not use your credential, unless there's some difference between a WinXP and Win 2003 relating to this behavior.  Is there some kind of thing like Run as administrator in Windows 2003, something like you would do in a vista environment?  I think default permissions are more strict in a windows server rather than in an XP box.

Are you also a member of the Administrator group in the machine?

Jul 8, 2009 at 4:33 PM

I tried to use an identical DBtracelistener in a windows application and it works fine as desired. I face thsi issue only when i am trying in my web application which uses a WCF.

Am really confused here :(


Jul 8, 2009 at 4:40 PM

So where does the logging part occurs, in the web application or in the WCF service?

Jul 8, 2009 at 4:42 PM

WCF service

Jul 8, 2009 at 4:44 PM

Ah, that gives us a hint, check out this link - http://blogs.msdn.com/wenlong/archive/2006/05/18/600603.aspx.  Do let me know if this solves the problem, would appreciate it.

Jul 8, 2009 at 5:09 PM

I have already specified the [OperationBehavior(Impersonation=ImpersonationOption.Required)] attribute for the service methods. Have placed a sample of the cWCF service method below

 [OperationBehavior(Impersonation = ImpersonationOption.Required)]       
        public int SampleMethod(EntityProtocol entityInput)
                int x = Convert.ToInt32("X");
                return x;
            catch (Exception ex)

                Exception ex_new = null;
                ExceptionPolicy.HandleException(ex, Constants.EX_HANDLE_POLICY_PRIMARY, out ex_new);
                throw ex_new;


Jul 8, 2009 at 5:13 PM

Still no luck?  Could you debug and execute the WindowsIdentity.GetCurrent().Name and see if it still returns the machine credential.

Jul 8, 2009 at 5:21 PM

The WindowsIdentity.GetCurrent().Name gives me "ITLINFOSYS\rajasoorya_KC". Its been so from the start. But when i use DBLoggin using HandleException the credential passed seems to be "ITLINFOSYS|CHNMCT90199$"

Jul 8, 2009 at 5:24 PM
Edited Jul 8, 2009 at 5:29 PM

Yes I get that, however, I was not aware a while ago that wcf is also involved so I assumed that that code was executing in asp.net.  I just needed to verify that impersonation worked in your wcf service. 

Wait, I have forgot to ask if you have followed the steps in integrating Logging application block with WCF.  It's in the documentation.

Jul 8, 2009 at 5:26 PM

Are you saying that EL could be behaving in a different way since it's been called from a WCF?

Jul 8, 2009 at 5:31 PM
Edited Jul 8, 2009 at 5:32 PM

Yes, there's extra steps you need to do in order to get LAB work with WCF.  It's in the documentation.  Can't believe I forgot to ask this at once.

Jul 8, 2009 at 5:55 PM

I found the procedure placed below in the documentation.  What is the use of the XMLTranceListener here? My requirement is to log in a DB. Should i follow the procedure for my requirement?

To configure the WCF-integration trace listeners

  1. Create or open a configuration file in one of the Enterprise Library configuration tools, and ensure the Logging Application Block is added to the application’s configuration. For more information, see Configuring Enterprise Library.
  2. Right-click the Trace Listeners node point to New, and then click XML Trace Listener.
  3. (Optional) In the properties pane, set the Name, the FileName for the trace file, and select a value for the TraceOutputOptions property to specify which options, or elements, should be included in the trace output.
  4. Right-click the Category Sources node, point to New and then click Category.
  5. In the properties pane, set the Name to System.ServiceModel.
  6. Right-click the System.ServiceModel node in the tree view, click New, and then click Trace Listener Reference.
  7. In the Properties pane, select ReferencedTraceListener, click the down-arrow button and select the XML Trace Listener.
  8. Save the configuration file.
  9. Open the configuration file either in Visual Studio or in the text editor of your choice.
  10. Define the EntLib Proxy Trace Listener in the <system.diagnostics> section and use System.ServiceModel as the source. (See the sample configuration file.)
  11. Modify the WCF configuration to specify the desired level of logging as shown in the following sample configuration file.

Jul 8, 2009 at 6:07 PM

The XmlTraceListener was just used as a sample.  You could substitute that with you database tracelistener.

Jul 8, 2009 at 6:46 PM

Below ar the steps i followed. But doesnt seem to solve the issue 

1. Created a DBTraceListener and configured its properties
2. Added a new category names "System.ServiceModel"
3. Added the DBTraceListener as the trace listener for the category
4. Created a policy for the exception type "System.Exception"
5. Added a logging handler to the policy
6. Modified the category of the logging handler to be "System.ServiceModel"
7. Modified the <system.diagnostics> as
      <source name="System.ServiceModel" switchValue="All" propagateActivity="true">
          <!--<add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          <add name="traceListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EntLibLoggingProxyTraceListener,Microsoft.Practices.EnterpriseLibrary.Logging" />
8. Modified <diagnostics> as
      <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtTransportLevel="true" />

Jul 9, 2009 at 2:28 AM

Is it still the same error?

You might not have followed the exceptionhandling integration with WCF as well, please refer to this blog - http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/04/07/Shielding-WCF-Services-with-Exception-Handling-Application-Block-_2D00_-Part-1.aspx.  Sorry for this late info, it was already past midnight when I was answering your question, must be the drowsiness.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Jul 9, 2009 at 7:07 AM


I went through the blog. It basically says about throwing the exceptions caught at the WCF as faults which i have already implemented using fault contracts :(

Since faults being the way exception is thrown, how will this impact the exception logging in the WCF which will happen before the fault conversion?

Thanks for the extended support i am provided with :)

Jul 14, 2009 at 8:10 AM

It will log the original exception which occured, not the converted one.  Do you still get the same error? 


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Jul 14, 2009 at 8:17 PM

I still face the same error :(


Jul 15, 2009 at 10:38 AM

Still cant log to the database? still the same error? Is your database in a remote computer?

I read this one that might be a hint "If SQL Server is running on a remote computer and the Web server is running IIS 6.0, give the Web server's machine account login privileges on the remote computer. The machine account is referenced as DOMAIN\MACHINENAME$.", maybe you've not granted your machine name login privileges. Taken from : http://msdn.microsoft.com/en-us/library/ab4e6cky(VS.80).aspx

Also, found some links that says possible work around for the error:

May 12, 2010 at 3:20 PM
rajasoorya, do you remember if you were able to fix this issue? We are having exactly same issue.. :(
May 13, 2010 at 3:41 AM

I missed the RevertImpersonation setting in the Logging Application Block.  It should be set to false.

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.