2014-08-30 37 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

相关问题