{system.invalidoperationexception: invalid operation.} The connection is closed.

Source: Internet
Author: User

C # using OLE DB to manipulate access
Provider=Microsoft.Jet.OLEDB.4.0;Data source= "+ NewFileName +"; User Id=uid; Jet oledb:database password=pwd; ";

Complete error message:
{system.invalidoperationexception: invalid operation.} The connection is closed.
In System.Data.ProviderBase.DbConnectionClosed.BeginTransaction (IsolationLevel il)
In System.Data.OleDb.OleDbConnection.BeginTransaction (IsolationLevel isolationlevel)
In System.Data.OleDb.OleDbConnection.BeginTransaction ()
In ProgramDialog.AddNew.button1_Click (Object sender, EventArgs e) Location Programdialog\addnew.cs: line number 79
In System.Windows.Forms.Control.OnClick (EventArgs e)
In System.Windows.Forms.Button.OnClick (EventArgs e)
In System.Windows.Forms.Button.OnMouseUp (MouseEventArgs mevent)
In System.Windows.Forms.Control.WmMouseUp (message& m, mousebuttons button, Int32 clicks)
In System.Windows.Forms.Control.WndProc (message& m)
In System.Windows.Forms.ButtonBase.WndProc (message& m)
In System.Windows.Forms.Button.WndProc (message& m)
In System.Windows.Forms.Control.ControlNativeWindow.OnMessage (message& m)
In System.Windows.Forms.Control.ControlNativeWindow.WndProc (message& m)
In System.Windows.Forms.NativeWindow.DebuggableCallback (IntPtr hWnd, Int32 msg, INTPTR wparam, INTPTR lparam)
In System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW (msg& MSG)
In System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMess Ageloop (IntPtr Dwcomponentid, Int32 reason, Int32 pvloopdata)
In System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Int32 reason, ApplicationContext context)
In System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 reason, ApplicationContext context)
In System.Windows.Forms.Application.RunDialog (Form form)
At System.Windows.Forms.Form.ShowDialog (IWin32Window owner)
In System.Windows.Forms.Form.ShowDialog ()
In Mainfrm.shownewform (Object sender, EventArgs e) Location Main.cs: line number 32
In System.Windows.Forms.ToolStripItem.RaiseEvent (Object key, EventArgs e)
In System.Windows.Forms.ToolStripButton.OnClick (EventArgs e)
In System.Windows.Forms.ToolStripItem.HandleClick (EventArgs e)
In System.Windows.Forms.ToolStripItem.HandleMouseUp (MouseEventArgs e)
In System.Windows.Forms.ToolStripItem.FireEventInteractive (EventArgs E, Toolstripitemeventtype met)
In System.Windows.Forms.ToolStripItem.FireEvent (EventArgs E, Toolstripitemeventtype met)
In System.Windows.Forms.ToolStrip.OnMouseUp (MouseEventArgs mea)
In System.Windows.Forms.Control.WmMouseUp (message& m, mousebuttons button, Int32 clicks)
In System.Windows.Forms.Control.WndProc (message& m)
In System.Windows.Forms.ScrollableControl.WndProc (message& m)
In System.Windows.Forms.ToolStrip.WndProc (message& m)
In System.Windows.Forms.Control.ControlNativeWindow.OnMessage (message& m)
In System.Windows.Forms.Control.ControlNativeWindow.WndProc (message& m)
In System.Windows.Forms.NativeWindow.DebuggableCallback (IntPtr hWnd, Int32 msg, INTPTR wparam, INTPTR lparam)
In System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW (msg& MSG)
In System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMess Ageloop (IntPtr Dwcomponentid, Int32 reason, Int32 pvloopdata)
In System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Int32 reason, ApplicationContext context)
In System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 reason, ApplicationContext context)
In System.Windows.Forms.Application.RunDialog (Form form)
At System.Windows.Forms.Form.ShowDialog (IWin32Window owner)
In System.Windows.Forms.Form.ShowDialog ()
In Program.main () position Program.cs: line number 751}

cause of error:
When using transaction transaction to operate the database, connection is not open or closed;

Workaround:
If the database connection is not open, call: Connection.Open ();

if (Connection.State == ConnectionState.Closed){    Connection.Open();}

If the database does not have a password, you do not need to add the following "User Id=uid; Jet oledb:database password=pwd; ".

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

{system.invalidoperationexception: invalid operation. The connection is closed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.