搜索内容

有一个问题?

如果您有任何疑问,可以在下面询问或输入您要寻找的!

当前线程处于堆栈溢出状态

技术聚客 未结 1 945
mjmlzj
mjmlzj 2021-03-01 10:41

“System.StackOverflowException”类型的未经处理的异常在 BLL.dll 中发生,使用的是Visual Studio 2012的,在输入用户名和密码后点击登陆,就会出现堆栈的问题,麻烦各位大哥帮忙看下是哪里出现问题了?谢谢!!

 

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Models; using DAL; using System.Web; namespace BLL { public class SysAdminManger { //根据用户名和密码查询 public SysAdmin AdminLogin(SysAdmin objAdmins) { objAdmins = new SysAdminManger().AdminLogin(objAdmins);//这段代码出现堆栈 if (objAdmins!= null) { HttpContext.Current.Session["currentName"] = objAdmins; } return (objAdmins); } } } <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <!DOCTYPE html> <html> <head runat="server"> <meta name="viewport" content="width=device-width" /> <title>AdminLogin</title> </head> <body> <div> <form action="/SysAdmin/AdminLogin" method="post"> 用户名:<input type="text" name="loginld" /> 密码:<input type="text" name="password" /> <input type="submit" value="登陆" /> </form> <%=ViewData["info"] %> </div> </body> </html> using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Models; using BLL; namespace KKS.Controllers { public class SysAdminController : Controller { // // GET: /SysAdmin/ public ActionResult Index() { return View("AdminLogin"); } public ActionResult AdminLogin() { //获取到页面的数据 SysAdmin objAdmins = new SysAdmin() { loginld = Convert.ToInt32(Request.Params["loginld"]), password = Request.Params["password"] }; //调用业务逻辑 objAdmins = new SysAdminManger().AdminLogin(objAdmins); if (objAdmins!= null) { ViewData["info"] = "欢迎你!" + objAdmins.Admins; } else { objAdmins = null; } return View(); } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Models; using System.Data; using System.Data.SqlClient; namespace DAL { public class SysAdminService { //根据用户名和密码来查询 public SysAdmin AdminLogin(SysAdmin objAdmins) { string sql ="select l_name from Admins where l_name='{1}"; sql = string.Format(sql, objAdmins.Admins, objAdmins.loginld,objAdmins.password); //查询 try { SqlDataReader objReader=Helper.SqlHelper.GetReader(sql); if(objReader.Read()) { objReader["Adminname"].ToString(); objReader.Close(); } else { objReader = null; } } catch(Exception ex) { throw new Exception("应用程序或数据库出错"+ex.Message); } return objAdmins; } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Configuration; using System.Data; using System.Data.SqlClient; namespace DAL.Helper { //数据通用类 public class SqlHelper { //连接字符串connString private static readonly string connString = ConfigurationManager.ConnectionStrings["connString"].ToString(); public static int Update(string sql) { SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand(sql, conn); try { conn.Open(); return cmd.ExecuteNonQuery(); // int result= cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } } //执行单一的结果查询 public static object GetSingleResult(string sql) { SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand(sql, conn); try { conn.Open(); return cmd.ExecuteScalar(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } } //结果集的查询 public static SqlDataReader GetReader(string sql) { SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand(sql, conn); try { conn.Open(); return cmd.ExecuteReader(CommandBehavior.CloseConnection); } catch (Exception ex) { conn.Close(); throw ex; } } } }

 

1条回答
  • 2021-03-01 11:21

    new SysAdminManger().AdminLogin(objAdmins) 方法循环递归调用了,方法内一直调用AdminLogin方法、绝对堆栈溢出了

    0 讨论(0)
提交回复