ServerVersion异常,无效操作。连接被关闭。

Kanderliu 2006-10-18 09:27:58
////////////////////////////////////////////////
private DataSet ExecuteSQL4DS(string strSQL)
{
try
{
OleDbDataAdapter currentDA = new OleDbDataAdapter(strSQL, oleDbConnection1);
DataSet ds = new DataSet("ds");
currentDA.Fill(ds);
return ds;
}
catch (OleDbException ex)
{
return null;
}
}
////////////////////////////////////////////////
oleDbConnection1断点跟踪出现的异常。

----ServerVersion “oleDbConnection1.ServerVersion”引发了“System.InvalidOperationException”类型的异常 string {System.InvalidOperationException}

----base {"无效操作。连接被关闭。"} System.Exception {System.InvalidOperationException}

----StackTrace " 在 System.Data.ProviderBase.DbConnectionClosed.get_ServerVersion()\r\n 在 System.Data.OleDb.OleDbConnection.get_ServerVersion()" string

////////////////////////////////////////////////
在我的2003系统的机子调试,虽然有异常,但是不会出错。还是能执行下去return ds。再另外一台2003系统的机器,却卡在这里不能执行了。catch到异常返回null。
...全文
3654 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Kanderliu 2006-10-18
  • 打赏
  • 举报
回复
找到问题了,谢谢大家的关注,现在给大家解答,顺便送分。

问题在于:State Closed System.Data.ConnectionState
连接没有open().

在try中加入
if (oleDbConnection1.State != ConnectionState.Open)
oleDbConnection1.Open();

加上
finally
{
if (oleDbConnection1.State != ConnectionState.Close)
{
oleDbConnection1.Close();
}
}
feiyun0112 2006-10-18
  • 打赏
  • 举报
回复
为什么不用 System.Data.OracleClient


*****************************************************************************
欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码)
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
lxhvc 2006-10-18
  • 打赏
  • 举报
回复
可能是Oracle客户安装有问题,看看那台机器上是不是装了多个Oracle客户端
lxhvc 2006-10-18
  • 打赏
  • 举报
回复
从异常提示来看是Connection对象初始化的异常,请贴出oleDbConnection1相关代码
xingyaohua 2006-10-18
  • 打赏
  • 举报
回复
up
Kanderliu 2006-10-18
  • 打赏
  • 举报
回复
连接窜的信息是正确的.

oleDbConnection1的信息:

- oleDbConnection1 {System.Data.OleDb.OleDbConnection} System.Data.OleDb.OleDbConnection
+ base {System.Data.OleDb.OleDbConnection} System.Data.Common.DbConnection {System.Data.OleDb.OleDbConnection}
ConnectionString "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=yjfb;Password=yjfb3g;Data Source=HPLIU;Extended Properties=''" string
ConnectionTimeout 15 int
Database "" string
DataSource "HPLIU" string
Provider "OraOLEDB.Oracle.1" string
- ServerVersion “oleDbConnection1.ServerVersion”引发了“System.InvalidOperationException”类型的异常 string {System.InvalidOperationException}
- base {"无效操作。连接被关闭。"} System.SystemException {System.InvalidOperationException}
- base {"无效操作。连接被关闭。"} System.Exception {System.InvalidOperationException}
+ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
HelpLink null string
+ InnerException null System.Exception
Message "无效操作。连接被关闭。" string
Source "System.Data" string
StackTrace " 在 System.Data.ProviderBase.DbConnectionClosed.get_ServerVersion()\r\n 在 System.Data.OleDb.OleDbConnection.get_ServerVersion()" string
+ TargetSite {System.String get_ServerVersion()} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
+ 静态成员
+ 非公共成员
State Closed System.Data.ConnectionState
+ 静态成员
+ 非公共成员



feiyun0112 2006-10-18
  • 打赏
  • 举报
回复
看看oleDbConnection1的连接字符串

*****************************************************************************
欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码)
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html

111,098

社区成员

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

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

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