Paolo ponzano - 313 - Feb 18, 2014

Excuse me how do I get the SQL Exception thrown in a call using the ExecuteNonQuery…what I get on the client is SqlException “Input string was an incorrect format” but in the deep it’s a costraint exception…

Consider this call
   var section = (NameValueCollection)ConfigurationManager.GetSection(“storedProcedure”);
            string storedProcedure = section.Get(“someSP”);

            var res = Db.Exec(dbCmd =>
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.CommandText = storedProcedure;

                dbCmd.Parameters.Add(new SqlParameter(“xxx”, request.IDxxx));

                return dbCmd.ExecuteNonQuery();
            });

That is the raw Exception is thrown by the ADO.NET provider and OrmLite doesn’t add any wrappers to it. Check to see if the InnerException has more info.

paolo ponzano:

Excuse me Demis, I’ve checked with fiddler…and I think the problem is during the SS client processing…my json is

{“responseStatus”:{“errorCode”:“SqlException”,“message”:“The INSERT statement conflicted with the CHECK constraint “CK_SOME_CONSTRAINT”. The conflict occurred in database “TEST_XXX”, table “dbo.SOME_TABLE”.\r\nThe statement has been terminated.”,“stackTrace”:"[MyDTORequest: 19/02/2014 07:29:11]:\n[REQUEST: {idIstituto:xx,codice:cod,descrizione:c,flaG_F_O:F,iD_MERCATO:0,iD_TIPOLOGIA_PRODOTTO:101,iD_DIVISA:AED,iD_TIPO_REGOLAMENTO:0,iD_MARGIN_STYLE:0,iD_TIPO_RAPPRESENTAZIONE_PREZZO:0,iD_UTENTE:185560,iD_MACROCATEGORIA_COMMERCIALE:0,divisorE_PREZZO:0}]\nSystem.Data.SqlClient.SqlException (0x80131904): The INSERT statement conflicted with the CHECK constraint “CK_CONSTRAINT”. The conflict occurred in database “TEST_XXX”, table “dbo.SOME_TABLE”.\r\nThe statement has been terminated.\r\n   at MYNamespace.service.Any(MYDTORequest request) in cxxx.cs:line 163\r\n   at ServiceStack.Host.ServiceRunner`1.Execute(IRequest request, Object instance, TRequest requestDto)\r\nClientConnectionId:53921837-e741-4a96-bd7e-5763b648b1b6",“errors”:[]}}.

And what I got on the Error(x=> is SQLException and as innerexception “Input string was not in a correct format”)

paolo ponzano:

I’ve checked the stack trace…it seems to be an exception with the deserializer

   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.Int32.Parse(String s, IFormatProvider provider)
   at ServiceStack.Text.Common.DeserializeBuiltin1.&lt;GetParseFn&gt;b__5(String value)<br>&nbsp;&nbsp; at ServiceStack.Text.Common.JsReader1.<>c__DisplayClassb1.&lt;GetCoreParseFn&gt;b__7(String value)<br>&nbsp;&nbsp; at ServiceStack.Text.Json.JsonReader1.Parse(String value)
   at ServiceStack.Text.JsonSerializer.DeserializeFromString[T](String value)
   at ServiceStack.Text.JsonSerializer.DeserializeFromStream[T](Stream stream)
   at ServiceStack.Serialization.JsonDataContractSerializer.DeserializeFromStream[T](Stream stream)
   at ServiceStack.JsonServiceClient.DeserializeFromStream[T](Stream stream)
   at ServiceStack.ServiceClientBase.HandleResponse[TResponse](WebResponse webResponse)
   at ServiceStack.ServiceClientBase.Send[TResponse](String httpMethod, String relativeOrAbsoluteUrl, Object request)
   at ServiceStack.ServiceClientBase.Post[TResponse](String relativeOrAbsoluteUrl, Object requestDto)
   at ServiceStack.ServiceClientBase.Post[TResponse](Object requestDto)
   at myRepo.InsertProdottoFromScratchAsync(Int32 idIstituto, Int32 idUtente, String codice, String descrizione, String flagFO, Int32 idMercato, Int32 idTipologiaProdotto, String idDivisa, Int32 idTipoRegolamento, Int32 idMarginStyle, Int32 idTipoRappresentazionePrezzo, Nullable1 durataNozioanle, Nullable1 tassoNozionale, Nullable1 idTipologiaMerci, Nullable1 codProvinciaEmittente, Nullable1 idTipoContrattoRischiMercato, String underIsin, String underProd, Nullable1 underGGValuta, Nullable`1 […]

That JSON deserializes correct for me, e.g:

var json = “…”;
var dto = json.FromJson<ErrorResponse>();
dto.PrintDump();

I’ve even tried it with an Italian Culture set, see commit: https://github.com/ServiceStack/ServiceStack.Text/commit/cf8f57e9600f8ee013e534eb631c548942e35a18

Can you post an issue on https://github.com/ServiceStack/Issues that shows a repro including the C# call you’re making and DTO’s you’re using and the Fiddler responses.

paolo ponzano:

Hello Demis,
I’ve managed right now to get the exception…it’s inside the ResponseStatus…that’s ok
((ServiceStack.WebServiceException)ex).ResponseStatus.Message … I was thinking of finding it inside ex.InnerException

ok great.
__________