class BaseData
{
public string DbConnection = ConfigurationManager.ConnectionStrings["OLTPPOINTER_Connectionstring"].ConnectionString;
public string DbConnection_Report = ConfigurationManager.ConnectionStrings["OLTPPOINTER_Connectionstring"].ConnectionString;
protected SqlConnection OpenConnection()
{
**SqlConnection conn = new SqlConnection(DbConnection);**----"StackOverflow Exception was unhandled"
try
{
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
return conn;
}
catch { throw; }
}
我使用了递归,它有时没有异常。 在某些情况下,它会抛出异常: -
SqlConnection conn = new SqlConnection(DbConnection);
or
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
adpt.Fill(ds, "DataSet");
CloseConnection(cmd.Connection);
递归调用使得抛出一个Exception.How来处理它
答案 0 :(得分:0)
是的,递归意味着嵌套的方法调用。太多嵌套方法调用确实会抛出StackOverflow
。你应该避免以递归方式打开多个连接。