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.