2014-08-30 36 views
0

我在asp.net c#中使用linq和oracle數據庫做了一個應用程序。此應用程序在Widows 7 32位本地主機上正常工作。但是當我在Windows Server 2008 r2中部署此應用程序時給出了以下error.Guide我什麼是以下error.How我可以檢查部署服務器上這個錯誤,我怎麼能解決這個錯誤指定的轉換無效。錯誤顯示在窗口服務器2008 r2

Specified cast is not valid. 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.InvalidCastException: Specified cast is not valid.

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:

[InvalidCastException: Specified cast is not valid.]

System.Data.UnboxT`1.ValueField(Object value) +54

sis.<>c__DisplayClass55.b__0(DataRow r) +38

System.Linq.WhereEnumerableIterator`1.MoveNext() +156

System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +165

System.Linq.d__81`1.MoveNext() +472

System.Linq.Enumerable.Count(IEnumerable`1 source) +267

sis.regreport.Page_Load(Object sender, EventArgs e) +5015

System.Web.UI.Control.LoadRecursive() +71

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean

includeStagesAfterAsyncPoint) +3178

var vcolM = dt.AsEnumerable() 
      .Where(r => r.Field<string>("MAJ") == (string)vprglist 
      && r.Field<string>("SPEC") == (string)vspecourse 
      && r.Field<string>("L_ABR_CODE") == (string)genderEng[1] 
      && r.Field<string>("reg") == (string)drRegion["reg"] 
      && r.Field<decimal>("year") == syrcnt) 
      .Sum(r => Convert.ToInt32(r["strength"])); 

所有LINQ像以上工作在當地pc.But罰款在windows server 2008中發生錯誤。在syrcnt是int的情況下。

+0

將斷點上線,並準確檢查是什麼類型的對象鍵。當你知道這一點時,你將處於一個更好的位置來研究你需要什麼類型的演員。 – 2014-08-30 10:40:57

+0

因爲在deploymnet服務器中我怎樣才能插入中斷點 – 2014-08-30 10:43:08

+0

因爲在開發服務器上只有DLLs文件可用。但是在本地pc應用程序中工作正常 – 2014-08-30 10:44:34

回答

0

InvalidCastException最可能的原因是r.Field<string>("MAJ") , r.Field<decimal>("year")行。如果數據的實際類型與傳遞給Field<T>的類型不匹配,則Field<T>擴展方法將拋出InvalidCastException

OR

就出在這裏Convert.ToInt32(r["strength"]),實力可能無法得到適當的類型

老實說,我覺得你的問題在於線r.Field<decimal>("year")。因爲沒有有關的數據類型多的信息,我可能是錯的變量syrcnt

因此給你的例外System.InvalidCastException: Specified cast is not valid

+0

syrcnt是int因爲我使用這是在for(int syrcnt = 0; ...) – 2014-08-30 12:05:48

+0

但這是在本地主機 – 2014-08-30 12:19:41

+0

是否有任何方法來檢查部署服務器中的錯誤 – 2014-08-30 12:20:08

相關問題