System.Data.OleDb.OleDbException: 未指定的错误(高分在线等)

ybs9999 2010-06-28 11:35:03
在向数据库写入数据时出现以下提示;但是刚把网站挂上去的时候是没问题的,大概添加了20多条记录后就出现错误了,而且什么都不用管,等待一会,错误就又没有了,又可以写入数据库了,然后如此循环。问题的原因在哪里呢?该怎么解决呢??


“/”应用程序中的服务器错误。

未指定的错误

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Data.OleDb.OleDbException: 未指定的错误

源错误:

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。

堆栈跟踪:


[OleDbException (0x80004005): 未指定的错误]
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +969373
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +86
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +29
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +4863644
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.OleDb.OleDbConnection.Open() +40
Yabbi.Dao.OleDao.GetDataReader(String sqlText) +71
pms_applymain.Page_Load(Object sender, EventArgs e) +344
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

版本信息: Microsoft .NET Framework 版本:2.0.50727.3603; ASP.NET 版本:2.0.50727.3082
...全文
703 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
jx_shen 2011-04-26
  • 打赏
  • 举报
回复
我也遇到了同样的问题,怎么解决啊!
  • 打赏
  • 举报
回复
在DBHelper 里面的
在最上面写上 protected OleDbConnection conn = null;
protected OleDbDataReader ExecuteReader(string cmdText, OleDbParameter[] pa)
{
conn = new OleDbConnection(connectionString); //然后 这个地方调用 这个conn
OleDbCommand cmd = new OleDbCommand();
try
{

PrepareCommand(cmd, conn, null, CommandType.Text, cmdText, pa);
dr = cmd.ExecuteReader();
cmd.Parameters.Clear();
return dr;
}
catch (Exception)
{
conn.Close();
conn.Dispose();
throw;
}
finally
{
}
}

在数据访问层里调用这个方法的时候
public ServicesType GetCompanyNewsTypeById(int id)
{
string sql = "SELECT * FROM ServicesType WHERE Id = @Id";

try
{
ServicesType servicesType = null;
OleDbParameter[] pa = { new OleDbParameter("@id", id) };
dr = ExecuteReader(sql, pa);
if (dr.Read())
{
servicesType = new ServicesType();
servicesType.Id = Convert.ToInt32(dr["id"]);
servicesType.STypeName = dr["sTypeName"].ToString();
}
dr.Close();
dr.Dispose();
conn.Close(); //在这个地方 再把那个 conn close掉 并 Dispose掉 就不会出 现链接次数过多而出现错误了
conn.Dispose();
return servicesType;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
sparkyu01 2010-06-30
  • 打赏
  • 举报
回复
LS正解,应该在finally中加close,保证连接总是会被关闭。
yourname386 2010-06-30
  • 打赏
  • 举报
回复
使用 dbConnection.Open()打开连接后
在try语句中加上fianlly语句,在fianlly语句中使用权dbConnection.Close()关闭连接

不要闲麻烦,要记住每次查询或更新数据时打开连接,执行对数据库数据的操作,关闭连接
ybs9999 2010-06-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 amandag 的回复:]

看下代码中数据库连接是否关闭,如果使用了DataReader也看下使用完后是否及时关闭
[/Quote]

最新测试情况:
该关闭的都关闭了,只要用户一多,还是出现上述问题。
另外:
我是自定义了一个类:
public static OleDbDataReader GetDataReader(string sqlText)
{
OleDbDataReader dataReader = null;
OleDbConnection dbConnection = new OleDbConnection(ConnectionString);
dbConnection.Open();

OleDbCommand cmd = new OleDbCommand(sqlText, dbConnection);

try
{
dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);//执行查询,close后关闭Connection
}
catch (System.Exception oe)
{
string str = GetErrorMsg(oe.Message.ToString()); //错误信息
}

return dataReader;
}
然后再页面里调用:
string mysql1 = "select count(ID) as icount from pms_Project ";
OleDbDataReader myReader1 = null;
myReader1 = OleDao.GetDataReader(mysql1);
myReader1.Read();
这样是不是我只要在数据读取后调用myReader1.Close();就可以同时关闭myReader1和dbConnection了?(我在网上查到是这样的。)
ybs9999 2010-06-30
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 zhanlixin 的回复:]

还要检查OleDbConnection.Open()后加没加Close()
[/Quote]
我是自定义了一个类:
public static OleDbDataReader GetDataReader(string sqlText)
{
OleDbDataReader dataReader = null;
OleDbConnection dbConnection = new OleDbConnection(ConnectionString);
dbConnection.Open();

OleDbCommand cmd = new OleDbCommand(sqlText, dbConnection);

try
{
dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);//执行查询,close后关闭Connection
}
catch (System.Exception oe)
{
string str = GetErrorMsg(oe.Message.ToString()); //错误信息
}

return dataReader;
}
然后再页面里调用:
string mysql1 = "select count(ID) as icount from pms_Project ";
OleDbDataReader myReader1 = null;
myReader1 = OleDao.GetDataReader(mysql1);
myReader1.Read();
这样是不是我只要在数据读取后调用myReader1.Close();就可以同时关闭myReader1和dbConnection了?(我在网上查到是这样的。)
Zhanlixin 2010-06-28
  • 打赏
  • 举报
回复
还要检查OleDbConnection.Open()后加没加Close()
ybs9999 2010-06-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 amandag 的回复:]

看下代码中数据库连接是否关闭,如果使用了DataReader也看下使用完后是否及时关闭
[/Quote]
多谢各位提醒,已经在所有myReader.Read()后面加上了myReader.Close();再测试一下看看。
另外,如果直接用vs中的AccessDataSource控件的Insert()或是Update();是不是就不用关心资源是否释放的问题了,因为在我AccessDataSource中找不到类似Close()的方法。
ybs9999 2010-06-28
  • 打赏
  • 举报
回复
多谢各位提醒,已经在所有myReader.Read()后面加上了myReader.Close();再测试一下看看。
另外,如果直接用vs中的AccessDataSource控件的Insert()或是Update();是不是就不用关心资源是否释放的问题了,因为在我AccessDataSource中找不到类似Close()的方法。
RHCL 2010-06-28
  • 打赏
  • 举报
回复
检查程序代码,按3L,4L所述看~
zrrsj 2010-06-28
  • 打赏
  • 举报
回复
连接关了没
amandag 2010-06-28
  • 打赏
  • 举报
回复
看下代码中数据库连接是否关闭,如果使用了DataReader也看下使用完后是否及时关闭
宝_爸 2010-06-28
  • 打赏
  • 举报
回复
OleDbConnection 使用后Close了吗?
好像是资源泄漏
chengzq 2010-06-28
  • 打赏
  • 举报
回复
帮顶,暂不清楚是什么问题。
ybs9999 2010-06-28
  • 打赏
  • 举报
回复
没人关注吗?自己顶一个。

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧