none
BizTalk - WebService fails - Unable to cast object of type 'System.DBNull' to type 'System.String'. RRS feed

  • Question

  • Hi there, 

    1. WebServerA connects to SQLServer to retrieve a date 'datesLaterThan'
    2. Uses that date to query a WebService on WebServerB
    3. Everything was working fine since several days ago
    4. Suddenly the messages stopped arriving to BizTalk and on WebServerA we discovered the error (below)
    5. It looks like the system is providing an empty date, but the date is available in the database on SQLServer
    6. The user which is configured in the connection string on WebServerA is able to connect to the database
    7. SQLServer is available from WebServerA
    8. No relevant Event Log errors were discovered on either server

    I suspect some service went down and restart will help, but I would prefere to figure out the root cause of this ?

    What actions would you reccoment to be taken on WebServerA ?

    ERROR

    ---------------------------------------------------------------------------------------------------------------------------

    06/15/2016 18:01:18

    Type : System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

    Message : Unable to cast object of type 'System.DBNull' to type 'System.String'.

    Source : mscorlib

    Help link :

    Detail : An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:

    System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'.

      at LSB.Data.LSBProvider.RetrieveCafForms(DateTime datesLaterThan)

      at LSB.Business.LSBManager.RetrieveCafForms(DateTime datesLaterThan, IEnumerable`1 databasesToUse)

      at LSB.WCF.MainService.LSBService.RetrieveCafForms(DateTime datesLaterThan)

      at SyncInvokeRetrieveCafForms(Object , Object[] , Object[] )

      at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)

      at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)

      at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)

      at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)

      at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

    Action : http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault

    Code : System.ServiceModel.FaultCode

    Reason : Unable to cast object of type 'System.DBNull' to type 'System.String'.

    Data : System.Collections.ListDictionaryInternal

    TargetSite : Void HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage)

    HResult : -2146233087

    Stack Trace :

    Server stack trace:

      at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)

      at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)

      at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

      at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

      at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:

      at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

      at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

      at ESD.ESDDataService.ILSBService.RetrieveCafForms(DateTime datesLaterThan)

      at ESD.ESDDataService.LSBServiceClient.RetrieveCafForms(DateTime datesLaterThan)

      at MForms.Service.ESD.ESDService.ReadCafDataFromExternalProvider(DateTime datesLaterThan)

      at MForms.Service.ESD.ESDService.CafFormTimer_Elapsed(Object sender, ElapsedEventArgs e)

    Additional Info:

    MachineName : PRDUCTIONMMO01

    TimeStamp : 15/06/2016 17:01:18

    FullName : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

    AppDomainName : ESDService.exe

    ThreadIdentity :

    WindowsIdentity : NT AUTHORITY\SYSTEM

    Category: Debug

    Priority: 0

    EventId: 100

    Severity: Error

    Title:Enterprise Library Exception Handling

    Machine: PRDUCTIONMMO01

    Application Domain: ESDService.exe

    Process Id: 2064

    Process Name: E:\Program Files (x86)\CFLY FDG SEZ\ESD Scheduler\ESDService.exe

    Win32 Thread Id: 5384

    Thread Name:

    Extended Properties:

    ------------ DEBUG_EVENT_LOG_END ------------



    God bless you all :)

    Friday, June 17, 2016 8:49 AM

All replies

  • Looks like the SQL query is returning a NULL for some reason, and your webservice code is breaking while trying to convert the DBNull to string. Ideally, this should be handled within the webservice/WCF code. Check if the date value being returned from the database is DBNull, if yes then assign the date field/variable in WCF code to String.Empty instead (in the line where you are accessing/assigning from the web service response in your WCF code).

    Do you know the exact query that is causing this from your step1?

    "WebServerA connects to SQLServer to retrieve a date 'datesLaterThan'"

    If yes, try to run the same in SQL Server Management Studio. If you are getting back a NULL, you have to handle this within the WCF code in WebServerA as mentioned above.

    Ref-

    http://stackoverflow.com/questions/10631814/unable-to-cast-object-of-type-system-dbnull-to-type-system-string


    Thanks Arindam












    Friday, June 17, 2016 9:01 AM
    Moderator
  • Hi, 

    `First of all I'm not a developer, so I will not be able to alter the code at this moment.

    I have found the ESD XYZ Service and restarted it.

    Since then I got several 502 errors:

    Message : The remote server returned an unexpected response: (502) Fiddler - Connection Failed.
    Message : The remote server returned an error: (502) Bad Gateway. 

    Then they stop and the previous error appears gain:

    Reason : Unable to cast object of type 'System.DBNull' to type 'System.String'.

    Also, i notticed when I restart the service it was 14:43, the service runnes wvery 15 min:

    At 15:58 a new entry appears in the log with the familiar error. There is however something strange about it,namelyTimestamp: 14.58.03 is one hour late from the actual event:


    God bless you all :)

    Friday, June 17, 2016 3:10 PM
  • Also  the problem begun on 06/06/2016.

    When I'm querying the log from that day, I get an additional information:

    cat *.2016-06-06.1.log|grep Reason

    This error is not seen in the logs prior to the issue, not it is in the logs after.

    Any ideas ?


    God bless you all :)

    Friday, June 17, 2016 4:17 PM
  • This last error is a bit revealing - is your WCF service passing a DateTime field to a SQL stored proc? Seems like the DateTime value that is being passed is not valid/correct. Although, can't be sure if that error was a one-off. Do you see any instances of the above error even now?

    Another thing that you can check, already mentioned-

    Do you know the exact query that is causing this from your step1?

    "WebServerA connects to SQLServer to retrieve a date 'datesLaterThan'"

    If yes, try to run the same in SQL Server Management Studio. Do you receive a NULL?


    Thanks Arindam


    Friday, June 17, 2016 4:29 PM
    Moderator
  • I'm exploring the source code to find out the exact query, I will post it later. 

    Why do you  think the logger would use two different date formats and two different time zones ?


    God bless you all :)

    Friday, June 17, 2016 5:06 PM

    1. Restarting IIS iisreset /noforce

    1. Log now contains another interesting error

    Ideas ?


    God bless you all :)

    Friday, June 17, 2016 5:56 PM
  • How is this first webservice called? Are these the logs for the first webservice? The error looks like it is coming from the WCF service itself and not SQL Server. So first thing I would look for is how this webservice is being triggered/what calls this web service to call SQL Server. 

    The error is self-explanatory - that the credentials passed to the service did not work.If you open the web config for this webservice in IIS do you see an entry for security?

    We need more context. Which service log are you seeing? How is this service accessed, etc.?


    Thanks Arindam





    Friday, June 17, 2016 6:16 PM
    Moderator

    1. I restarted my server

    2. As soon as I restarted it, a new error popped up saying that there is no connection to http://127.0.0.1:8888

    3. Since telnet 127.0.0.1 8888 failed, I decided to edit .config file and coment out the section for default proxy

    1. The  System.DBNull error continues but now I noticed something else:

    Stack Trace :

    Server stack trace:

      at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)

      at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)

      at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

      at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

      at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)


    1. Do you think it’s relevant, if not then how was this server even started before ?

    2. No proxy has been found on that machine by looking inside appwiz.cpl

    3. How do I start the proxy on the localhost port 8888 please ?


    God bless you all :)

    Monday, June 20, 2016 11:14 AM
  • Hi

    Where is the above config file from? Is it the web.config for service A?

    Normally, 8888 port is used by Fiddler - so maybe someone was using Fiddler to debug on this server, and this entry was left over from that time? Are you able to browse the WebServiceB URL directly from WebServerA using IE? If yes, you don't/should not need a proxy in the config.


    Thanks Arindam


    Monday, June 20, 2016 12:08 PM
    Moderator
  • 1. The config sits in the same directory that the ESDService.e

    2. It's beginning to make sense, I've written about Fiddler 502 Bad Gateway error before. 

    3. So, the conclusion is;  whoever was working on that server before, was using Fiddler to debug the service, this is not documented so I'm on my own here...

    4. The service is now not pointed to Fiddler at the moment since the entry was commented out in the .config file but it is  still failing with System.DBNull

    5. Is it possible that the Fiddler, was not only used as a trafic visualization tool, but also as a manner of temp.  fix of the System.DBNull issue ?

    6. How do I check that, what config files should I be looking for etc. ?


    God bless you all :)

    Monday, June 20, 2016 1:46 PM
  • 5. Is it possible that the Fiddler, was not only used as a trafic visualization tool, but also as a manner of temp.  fix of the System.DBNull issue ?

    I would not think so. Unless fiddler was mocking the entire webserviceB. Is this production? In test env, etc. it could be that fiddler was being used to act as a mock service. I would guess that fiddler was being used to track the service requests and responses.

    To proceed from here-

    Can you elaborate on the application flow? How does the entire setup work? Who/what is supposed to call WebServiceA? Are you debugging this due to the error messages or, are users complaining that everything is broken?


    Thanks Arindam

    Monday, June 20, 2016 2:00 PM
    Moderator