Sqlite IDbConnection - BeginTransaction Execption

0

I have a Sqlite/C# Application and want to start a transaction but i always get this execption:

System.InvalidOperationException HResult=0x80131509 message= The operation is invalid due to the current state of the object.
Quelle = System.Data.SQLite Stapelüberwachung: bei System.Data.SQLite.SQLiteConnection.BeginDbTransaction(IsolationLevel isolationLevel) bei System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction() bei CsvCompare.database.importCSVtoDB(List`1 clist, String table) in C:\Users\Luis\source\repos\CsvCompare\CsvCompare\database.cs: Zeile40 bei CsvCompare.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\Luis\source\repos\CsvCompare\CsvCompare\Form1.cs: Zeile29
bei System.Windows.Forms.Control.OnClick(EventArgs e) bei System.Windows.Forms.Button.OnClick(EventArgs e) bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) bei System.Windows.Forms.Control.WndProc(Message& m) bei System.Windows.Forms.ButtonBase.WndProc(Message& m) bei System.Windows.Forms.Button.WndProc(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) bei System.Windows.Forms.Application.Run(Form mainForm) bei CsvCompare.Program.Main() in C:\Users\Luis\source\repos\CsvCompare\CsvCompare\Program.cs: Zeile19

I translated the execption. If you dont unterstand something then let me know.

Here is the code:

 public static void importCSVtoDB(List<customer> clist,string table)
        {
            string query = "";

            foreach (customer c in clist)
            {
                query +=  "INSERT INTO " + table + "(adress,name,zipcode,city) VALUES('" + c.adress + "','" + c.name + "'," + c.zipcode + ",'" + c.city + "');\n";
            }


            using (IDbConnection db = new SQLiteConnection(loadconnectionstring()))
            {
                db.BeginTransaction();
                db.Execute(query + "COMMIT;"); 

            }
        }

How i can solve this?

c#
database
sqlite
transactions
insert
asked on Stack Overflow Feb 9, 2020 by Luis Mehrweg

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0