0
Reply

Specified cast is not valid

praveenreddy

praveenreddy

Apr 26 2005 3:33 AM
2.3k
I got the following error message "Specified cast is not valid" Description: An unhandled exception occured during the execution of the current webrequest.Please review the stack trace for more information about the error and where it originates in the code. .NET Framework info: "Microsoft.NET\Framework\v1.1.4322" Message = Specified cast is not valid. Method = Session_Start StackTrace = at Global.Session_Start(Object sender, EventArgs e) Global.Session_Start method is here: protected void Session_Start(Object sender, EventArgs e) { // LOG THE NEW USER try { WindowsPrincipal principal = (WindowsPrincipal) Thread.CurrentPrincipal; Session["UserId"] = principal.Identity.Name ; // IF BOGUS USER FROM DEBUG OR SOMETHING THEN IGNORE if (Session["UserId"].ToString().Length < 3) return; Application.Lock(); Application["CurrentUsers"] = (int)Application["CurrentUsers"] + 1; Application.UnLock(); string sqlCmdStr = " Insert into UserLog (UserName, LoginTime) VALUES('" + Session["UserId"] +"', '" + DateTime.Now.ToString() + "')" ; SqlConnection conn = SQLDbUtils.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand(sqlCmdStr, conn); cmd.ExecuteNonQuery(); //Code to fetch user preference data from the database sqlCmdStr="Select * from UserPreferences where UserName='"+Session["UserId"].ToString() + "'"; SqlDataAdapter da = new SqlDataAdapter(sqlCmdStr,conn); DataSet tempdb= new DataSet(); da.Fill(tempdb,"UserPreferences"); } conn.Close(); } catch(Exception ex) { WebPageUtils.EventLogger(ex); }