System.Data.OleDb.OleDbException: 未指定的错误 !

mr1son 2010-11-14 09:53:36
网上找了很多文章来看。。好像都不行。。
源错误:
try
行 62: {
行 63: conn.Open();
行 64: dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
行 65: }



推跟中:
[OleDbException (0x80004005): 未指定的错误]
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +1054657
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +53
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +27
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +47
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.OleDb.OleDbConnection.Open() +37
ProductSort.GetProductSortAll() in d:\kaoshiung\App_Code\ProductSort.cs:63

[Exception: 未指定的错误]
ProductSort.GetProductSortAll() in d:\kaoshiung\App_Code\ProductSort.cs:68
productsort1.BindProductSortData() in d:\kaoshiung\productsort1.aspx.cs:60
productsort1.Page_Load(Object sender, EventArgs e) in d:\kaoshiung\productsort1.aspx.cs:30
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061



cs代码就这样

public OleDbDataReader GetProductSortByID(int nSortID)
{
OleDbConnection conn = db.CreateConnection();
string cmdText = "select * from productSort where sortID=" + nSortID;
OleDbCommand myCommand = new OleDbCommand(cmdText, conn);

OleDbDataReader dr = null;
try
{
conn.Open();
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (OleDbException ex)
{
throw new Exception(ex.Message, ex);
}
return dr;
}


...全文
176 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
mr1son 2010-11-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 qingfeng_wu 的回复:]

应该是连接字符串写得不对,仔细仔细的检查。
[/Quote]
我这个错误是一开始是没有的。。。连续点了几下就杯具了。。
mr1son 2010-11-14
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 teng_s2000 的回复:]

如果数据库连接串没有问题的话,尝试

public OleDbDataReader GetProductSortByID(int nSortID)
{
OleDbConnection conn = db.CreateConnection();
string cmdText = "select * from productSort where sortID=" + nSort……
[/Quote]
先感谢先。。不过问题还是这样。。。
Teng_s2000 2010-11-14
  • 打赏
  • 举报
回复
如果数据库连接串没有问题的话,尝试

public OleDbDataReader GetProductSortByID(int nSortID)
{
OleDbConnection conn = db.CreateConnection();
string cmdText = "select * from productSort where sortID=" + nSortID;
conn.Open();
OleDbCommand myCommand = new OleDbCommand(cmdText, conn);

OleDbDataReader dr = null;
try
{
conn.Open();
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (OleDbException ex)
{
throw new Exception(ex.Message, ex);
}
return dr;
}
吴青峰 2010-11-14
  • 打赏
  • 举报
回复
应该是连接字符串写得不对,仔细仔细的检查。
mr1son 2010-11-14
  • 打赏
  • 举报
回复
怎么没有人来啊。。呜呜。。。大神啊。。
mr1son 2010-11-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 phil999 的回复:]

OleDbConnection conn = db.CreateConnection();

连接字符串呢?
[/Quote]

写在令一个类里。。是这样的
public class db
{
public db()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static OleDbConnection CreateConnection()
{
String ConnStr = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING"].ConnectionString;
//ConnStr+=@"F:\Inetpub\company\App_Data\companyDB.mdb";
ConnStr += System.Web.HttpContext.Current.Server.MapPath("~/App_Data/companyDB.mdb");
return new OleDbConnection(ConnStr);
}
}
phil999 2010-11-14
  • 打赏
  • 举报
回复
OleDbConnection conn = db.CreateConnection();

连接字符串呢?
mr1son 2010-11-14
  • 打赏
  • 举报
回复
大神啊。。99我啊。。在线等啊。。
Irise_liu 2010-11-14
  • 打赏
  • 举报
回复
CreateConnection()里写好conn的开关,然后ExecuteReader()方法最好不用带参那个
get
{
if (conn == null)
{
conn = new SqlConnection(conStr);
conn.Open();
}
else if (conn.State == ConnectionState.Closed)
{

conn.Open();
}
else if (conn.State == ConnectionState.Broken)
{
conn.Close();
conn.Open();
}
return conn;
}
mr1son 2010-11-14
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 abcjun188 的回复:]

你确定你的连接都关了吗,在 catch后面加一个 finally{

//关闭连接什么什么的,该关的都关

}
[/Quote]
谢谢了。。问题我已经解决了。。。一切的根源都是这个CommandBehavior.CloseConnection
没有自动关闭。。
打一壶酱油 2010-11-14
  • 打赏
  • 举报
回复
你确定你的连接都关了吗,在 catch后面加一个 finally{

//关闭连接什么什么的,该关的都关

}
abcjun18 2010-11-14
  • 打赏
  • 举报
回复
你确定你的连接都关了吗,在 catch后面加一个 finally{

//关闭连接什么什么的,该关的都关

}
mr1son 2010-11-14
  • 打赏
  • 举报
回复
有没有人啊。。。。QQ263471432.。验证:大神。。


在线等啊。。

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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