2016-01-18 36 views
0

我有一個使用NHibernate鏈接到MySQL數據庫的項目。突然間,網頁開始拋出以下錯誤:確定哪個數據庫行導致「輸入字符串格式不正確」

Input string was not in a correct format. 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.FormatException: Input string was not in a correct format. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[FormatException: Input string was not in a correct format.] 
    System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +14281985 
    System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +305 
    System.SByte.Parse(String s, NumberStyles style, NumberFormatInfo info) +41 
    MySql.Data.Types.MySqlByte.MySql.Data.Types.IMySqlValue.ReadValue(MySqlPacket packet, Int64 length, Boolean nullVal) +182 
    MySql.Data.MySqlClient.NativeDriver.ReadColumnValue(Int32 index, MySqlField field, IMySqlValue valObject) +376 
    MySql.Data.MySqlClient.ResultSet.ReadColumnData(Boolean outputParms) +105 
    MySql.Data.MySqlClient.ResultSet.NextRow(CommandBehavior behavior) +263 
    MySql.Data.MySqlClient.MySqlDataReader.Read() +98 
    NHibernate.Driver.NHybridDataReader.Read() +28 
    NHibernate.Impl.MultiCriteriaImpl.GetResultsFromDatabase(IList results) +1363 

    [HibernateException: Error executing multi criteria : [SELECT count(distinct this_.ID) as y0_ FROM `PropertyItem` this_ WHERE (this_._Temporary_Flag = ?p0 or this_._Temporary_Flag is null) and (this_._Deleted = ?p1 or this_._Deleted is null) and this_.Featured = ?p2 and this_.Activated = ?p3 and this_.ListingStatus = ?p4 and this_.HideListingFromWeb = ?p5 and this_.HideListingFromPublic = ?p6; 
SELECT this_.ID as ID53_1_, this_.FullPropertyDescription as FullProp2_53_1_, this_.HeaderTagText as HeaderTa3_53_1_, this_.PropertyCategory as Property4_53_1_, this_.PropertyStatus as Property5_53_1_, this_.ShortDescription as ShortDes6_53_1_, this_.PropertyPrice as Property7_53_1_, this_.RefCode as RefCode53_1_, this_.Featured as Featured53_1_, this_.Title as Title53_1_, this_.StarRating as StarRating53_1_, this_.AmountOfBedrooms as AmountO12_53_1_, this_.Activated as Activated53_1_, this_.PropertyPlotSize as Propert14_53_1_, this_.PropertyFloorArea as Propert15_53_1_, this_.AmountOfBathrooms as AmountO16_53_1_, this_.AmountOfGarages as AmountO17_53_1_, this_.VirtualTourURL as Virtual18_53_1_, this_.RentInterval as RentInt19_53_1_, this_.HolidayPriceDescription as Holiday20_53_1_, this_.Exclusive as Exclusive53_1_, this_.FacebookImageFilename as Faceboo22_53_1_, this_.MainImageFilename as MainIma23_53_1_, this_.IsFromXMLFile as IsFromX24_53_1_, this_.PriceDaily as PriceDaily53_1_, this_.FeatureValuesForSearch as Feature26_53_1_, this_._LastEditedOn as column27_53_1_, this_.IsExclusive as IsExclu28_53_1_, this_.HidePriceFromPublic as HidePri29_53_1_, this_.ListingStatus as Listing30_53_1_, this_.HideListingFromWeb as HideLis31_53_1_, this_.LastXmlImportInfo as LastXml32_53_1_, this_.HideListingFromPublic as HideLis33_53_1_, this_._Temporary_LastUpdOn as column34_53_1_, this_._Temporary_Flag as column35_53_1_, this_._Deleted as column36_53_1_, this_._DeletedOn as column37_53_1_, this_.Priority as Priority53_1_, this_.LocalityID as LocalityID53_1_, this_.PropertyTypeID as Propert40_53_1_, this_._LastEditedByID as column41_53_1_, this_.OfficeNameID as OfficeN42_53_1_, this_.SalesAgentID as SalesAg43_53_1_, location2_.ID as ID36_0_, location2_.ReferenceID as Referenc2_36_0_, location2_.Title as Title36_0_, location2_.LocationType as Location4_36_0_, location2_._Temporary_LastUpdOn as column5_36_0_, location2_._Temporary_Flag as column6_36_0_, location2_._Deleted as column7_36_0_, location2_._DeletedOn as column8_36_0_, location2_.Priority as Priority36_0_, location2_.ParentLocationID as ParentL10_36_0_ FROM `PropertyItem` this_ left outer join `Location` location2_ on this_.LocalityID=location2_.ID WHERE (this_._Temporary_Flag = ?p7 or this_._Temporary_Flag is null) and (this_._Deleted = ?p8 or this_._Deleted is null) and this_.Featured = ?p9 and this_.Activated = ?p10 and this_.ListingStatus = ?p11 and this_.HideListingFromWeb = ?p12 and this_.HideListingFromPublic = ?p13 and this_.ID in (?p14, ?p15, ?p16, ?p17, ?p18, ?p19, ?p20, ?p21);]] 
     Classes.Search.DatabaseSearcher.GetSearchInDatabase() 
     System.Web.UI.Control.LoadRecursive() +71 
     System.Web.UI.Control.LoadRecursive() +190 
     System.Web.UI.BasePartialCachingControl.LoadRecursive() +143 
     System.Web.UI.Control.LoadRecursive() +190 
     System.Web.UI.Control.LoadRecursive() +190 
     System.Web.UI.Control.LoadRecursive() +190 
     System.Web.UI.Control.LoadRecursive() +190 
     System.Web.UI.Control.LoadRecursive() +190 
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178 

是否可以確定哪些行導致問題?由此產生的數據集非常大,難以一一瀏覽。

+1

只是調試代碼,看裏面的值數據集? –

+0

嘗試查看mysql工具中的實際數據 –

+0

從NHibernate/MySQL代碼中發生此錯誤。基本上,執行查詢時,數據不能轉換回C#類型,並且顯然正在生成錯誤。 –

回答

0

從你的錯誤消息的一些意見:

  1. 的NHibernate正試圖將字符串轉換成數字,和失敗。因此,您應該重點關注已映射到int屬性的varchar(或類似)列。看看你的NHibernate映射和CREATE TABLE陳述來找出哪些列可能是問題。
  2. SELECT count(...)不可能返回一個字符串,所以問題必須在別處。
  3. 它看起來像查詢已被截斷(....),並且您正在使用MultiCriteria,所以我懷疑此批次中有第二個或第三個SELECT查詢,實際上是造成問題。重點關注這些查詢的SELECT子句中列出的列。

一旦確定哪些列可能有罪,您可以識別哪些行包含那些列非整數的文字用一個簡單的SELECT查詢:How do I check to see if a value is an integer in MySQL?

+0

我已經更新了原始問題中SQL查詢中的完整WHERE子句。是的,關於你的觀點 - 這將有助於解決問題。但是,我的問題是我如何知道哪個是違規行,所以我可以修復它。問題可能是某個特定的db列與C#類型完全不匹配。我需要通過代碼庫,但是我想快速修復並更新數據,但是逐一瀏覽每行和每列的內容太單調乏味,特別是每行都有大量列。 –