{System.InvalidOperationException: 无效操作。连接被关闭。
2015-08-15 13:31
483 查看
C#使用OleDB操作ACCESS
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” + NewFileName + “;User Id=uid;Jet OLEDB:Database Password=pwd;”;
完整错误信息:
{System.InvalidOperationException: 无效操作。连接被关闭。
在 System.Data.ProviderBase.DbConnectionClosed.BeginTransaction(IsolationLevel il)
在 System.Data.OleDb.OleDbConnection.BeginTransaction(IsolationLevel isolationLevel)
在 System.Data.OleDb.OleDbConnection.BeginTransaction()
在 ProgramDialog.AddNew.button1_Click(Object sender, EventArgs e) 位置 ProgramDialog\AddNew.cs:行号 79
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.RunDialog(Form form)
在 System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
在 System.Windows.Forms.Form.ShowDialog()
在 MainFrm.ShowNewForm(Object sender, EventArgs e) 位置 Main.cs:行号 32
在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
在 System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.RunDialog(Form form)
在 System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
在 System.Windows.Forms.Form.ShowDialog()
在 Program.Main() 位置 Program.cs:行号 751}
错误原因:
在使用事务Transaction对数据库进行操作时,Connection没有Open或已经关闭;
解决方法:
如果没有打开数据 库连接,则调用:Connection.Open();方法;
如果数据 库没有密码,则不需要添加后面的“User Id=uid;Jet OLEDB:Database Password=pwd;”。
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” + NewFileName + “;User Id=uid;Jet OLEDB:Database Password=pwd;”;
完整错误信息:
{System.InvalidOperationException: 无效操作。连接被关闭。
在 System.Data.ProviderBase.DbConnectionClosed.BeginTransaction(IsolationLevel il)
在 System.Data.OleDb.OleDbConnection.BeginTransaction(IsolationLevel isolationLevel)
在 System.Data.OleDb.OleDbConnection.BeginTransaction()
在 ProgramDialog.AddNew.button1_Click(Object sender, EventArgs e) 位置 ProgramDialog\AddNew.cs:行号 79
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.RunDialog(Form form)
在 System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
在 System.Windows.Forms.Form.ShowDialog()
在 MainFrm.ShowNewForm(Object sender, EventArgs e) 位置 Main.cs:行号 32
在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
在 System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.RunDialog(Form form)
在 System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
在 System.Windows.Forms.Form.ShowDialog()
在 Program.Main() 位置 Program.cs:行号 751}
错误原因:
在使用事务Transaction对数据库进行操作时,Connection没有Open或已经关闭;
解决方法:
如果没有打开数据 库连接,则调用:Connection.Open();方法;
if (Connection.State == ConnectionState.Closed){ Connection.Open(); }
如果数据 库没有密码,则不需要添加后面的“User Id=uid;Jet OLEDB:Database Password=pwd;”。
相关文章推荐
- linux常用命令
- Hadoop如何升级版本_Hadoop1.x升级到2.x
- apache2问题
- Linux安装webbench压力测并发数
- hadoop系列:zookeeper(2)——zookeeper核心原理(选举)
- 配置安装Nagios启动apache时出现问题解决方法
- Linux下Nagios的安装与配置
- Iftop安装记录
- CentOS 6.4安装配置LAMP服务器
- 在Linux环境中搭建zabbix监控环境
- System.InvalidOperationException: ConnectionString 属性尚未初始化。
- CentOS下搭建openstack-Havana
- linux文件的类型和后缀名
- newlisp获得bash该命令的退出状态
- win下安装apache和tomcat集群
- Linux安装Tomcat 和Java-JDK
- 解读:Hadoop序列化类
- OpenGL ES 镜面光照
- 上网看什么?推荐10个有趣的网站给大家
- Tomcat修改端口