현재로서는 특정 사이트 (asp.net)를 php로 빌드 할 수있을 정도로 오래 유지하려고합니다. 그러나 .net 또는 asp.net에 대해 많이 알지 못합니다. 데이터베이스 또는 무언가로부터 결과를 캐스팅 문제가있는 것 같습니다지정한 캐스트가 유효하지 않습니다.
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:
Line 21: string conn = ConfigurationSettings.AppSettings["DSN"];
Line 22: string email = (Membership.GetUser(HttpContext.Current.User.Identity.Name)).Email;
Line 23: iD = (int)SqlHelper.ExecuteScalar(
Line 24: conn,
Line 25: CommandType.Text,
Source File: e:\PKwebSX\app_code\PKMembershipProvider.cs Line: 23
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
PKMembershipProvider.get_ID() in e:\PKwebSX\app_code\PKMembershipProvider.cs:23
ASP.mijnpk_ascx.Page_Load(Object sender, EventArgs e) in e:\PKwebSX\mijnpk.ascx:20
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +36
System.Web.UI.Control.OnLoad(EventArgs e) +102
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1064
Version Information: Microsoft .NET Framework Version:2.0.50215.44; ASP.NET Version:2.0.50215.44
:
우리는이 오류를 얻고있다. 사용 된 코드는 다음과 같습니다.
public sealed class PKMembershipProvider : SqlMembershipProvider
{
public int ID
{
get
{
int iD = 0;
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
string conn = ConfigurationSettings.AppSettings["DSN"];
string email = (Membership.GetUser(HttpContext.Current.User.Identity.Name)).Email;
iD = (int)SqlHelper.ExecuteScalar(
conn,
CommandType.Text,
"SELECT ID From ledenlijst WHERE email = '" + email + "'");
}
return iD;
}
}
}
어디에서 잘못 되었습니까?
코드 작성 방법은 SQL 문 "SELECT ID from ledenlijst"의 결과로 유효한 ID가 항상 필요합니다. InvalidCastException을 유발할 수있는 레코드가 리턴되지 않은 경우. ID가 int가 아닌 필드 인 경우 다른 원인이 될 수 있습니다. 이 코드는 때때로 작동하고 때때로 실패합니까? – rsbarro