0

When I try to make a thread and put my code in it I get the following error...

The code snippet in your post is formatted incorrectly. Please use the Code button in the editor toolbar when posting whitespace-sensitive text or curly braces.

I've no idea what I'm doing wrong, I've posted code many times in the past.

(edit)

here is the code in question.

/// <summary>
        /// Backs up a zipped folder to the database
        /// </summary>
        /// <param name="foldername">Name folder to backup</param>
        /// <param name="path">Path to the temp zip file</param>
        /// <param name="source">Path to the original folder location</param>
        /// <returns>True if successful, false if not</returns>
        private bool Backup(string foldername, string path, string source)
        {
            string hash = FileHash(path);

            Debug.WriteLine("Backup");
            Debug.WriteLine("foldername " + foldername);
            Debug.WriteLine("path " + path);
            Debug.WriteLine("source " + source);
            Debug.WriteLine("hash " + hash);

            SQLiteCommand cmd = new SQLiteCommand(db);

            bool backupexists = TableExists(foldername);

            Debug.WriteLine("Table exists " + backupexists.ToString());

            cmd.CommandText = "CREATE TABLE IF NOT EXISTS " + foldername + "(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT"
                + ", data BLOB"
            + ", tempfile VARCHAR(2048)"
            + ", sourcepath VARCHAR(2048)"
            + ", hash VARCHAR(32)"
            + ", updated datetime);";

            int rowsaffected = cmd.ExecuteNonQuery();

            Debug.WriteLine("rows affected " + rowsaffected.ToString());

            byte[] blob = null;

            try
            {
                blob = File.ReadAllBytes(path);
            }
            catch (Exception ex)
            {
                cmd.Dispose();
                MessageBox.Show("An error occurred reading file\nThe folder was not backed up\n error: " + ex.Message,
                    Properties.Settings.Default.AppName);
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                Debug.WriteLine("Fail ReadAllBytes");
                this.Invoke(new Dummy(() => { Thread1Complete(); }));
                return false;

            }

            DateTime date = DateTime.Now;

            cmd.CommandText = "INSERT INTO " + foldername + "(data, tempfile, sourcepath, hash, updated) VALUES (@bin, @temp, @source, @hash, @updated)";

            cmd.Prepare();
            cmd.Parameters.Add("@bin", DbType.Binary, blob.Length).Value = blob;
            cmd.Parameters.Add("@temp", DbType.String, path.Length).Value = path;
            cmd.Parameters.Add("@source", DbType.String, source.Length).Value = source;
            cmd.Parameters.Add("@hash", DbType.String, hash.Length).Value = hash;
            cmd.Parameters.Add("@updated", DbType.DateTime).Value = date;

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (SQLiteException ex) // <<<<<<<<<<<<<<< This exception occurs
            {
                Debug.WriteLine("Fail ExecuteNonQuery");
                Debug.WriteLine(ex.ToString());
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                this.Invoke(new Dummy(() => { Thread1Complete(); }));
                return false;
            }

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            Debug.WriteLine("Win");
            cmd.Dispose();
            this.Invoke(new Dummy(() => { Thread1Complete(); }));
            return true;
        }

(edit2)

hmm. it's working here.

Edited by Suzie999: adding code

2
Contributors
2
Replies
34
Views
2 Years
Discussion Span
Last Post by ddanbe
1

Suspect, you are using Visual Studio.
Why do you use the old fashioned method Debug.WriteLine?
Why not use the marvelous debugger who sits right under your fingertips?
Set some breakpoints and stroll through your code and watch variables change on the way! This is a nice article about it.

Edited by ddanbe: addition

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.