in

System.Data.SQLite

An open-source, enhanced version of the SQLite database engine for Windows

Strange error finding table when making call to MAPI32.dll

Last post 04-11-2008 3:28 PM by mastermel. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 04-11-2008 1:55 PM

    Strange error finding table when making call to MAPI32.dll

    Hey all, I've been using System.Data.SQLite in a project for several months now and have to say that I love it! It always works great. But just yesterday I've run accross a really strange incompatibillity that I can't seem to figure out. 

    I use SQLite several times throught my program to write values to a log file and a settings file. This always works as expected until I try and run the same code after I've made a call to a slick little MAPI32 wrapper that Andrew Baker wrote here:

    http://www.vbusers.com/codecsharp/codeget.asp?ThreadID=71&PostID=1

    After I've called his MapiMailMessage.ShowDialog(), the very next time I try and call any code for reading or writing to a database I get a table not found error.

    Here's a sample of one of the interactions with SQLite that I'm using:

    (This is written in C# by the way)

             private void setValueInDataBase(SettingsClient key, String value)
            {
                // Get the connection string for the database file
                String connectionString = SharedDAO.CreateSQLiteConnectionString(SettingsDBName);

                // Create the SQLite Connection
                using (SQLiteConnection conn = new SQLiteConnection(connectionString))
                {
                    // Open the connection
                    conn.Open();

                    // Create the transaction
                    using (SQLiteTransaction trans = conn.BeginTransaction())
                    {
                        // Create the SQLite Command
                        using (SQLiteCommand command = new SQLiteCommand(conn))
                        {
                            // Declare our query
                            command.CommandText = @"UPDATE client_settings
                                                    SET
                                                        Value = @value
                                                    WHERE
                                                        Key = @key"
    ;

                            // Add the parameter
                            command.Parameters.Add(new SQLiteParameter("@key", (int)key));
                            command.Parameters.Add(new SQLiteParameter("@value", value));

                            // Execute the query
                            try
                            {
                                command.ExecuteNonQuery();

                            }
                            catch (Exception exc)
                            {
                                //throw;
                                Console.WriteLine(exc.ToString());
                            }
                        }

                        // Commit the transaction
                        trans.Commit();
                    }
                }
            }

     

    I've been able to verify by a process of elimination that the actual code that determines whether an exception will be thrown is the line in Andrew's code that makes the call to the MAPI32.dll, namely:

       int error = MAPIHelperInterop.MAPISendMail(IntPtr.Zero, IntPtr.Zero, message, MAPI_DIALOG | MAPI_NEW_SESSION, 0);

    After this line, any time I attempt to interact with a SQLite table I get a table could not be found exception. 

     

    For the time being I'm looking for another way to create new emails and attach stuff to them. But it's kind of strange that this seemingly unrelated functionality would have an effect on my SQLite stuff.

    Any help on this would be greatly appreciated! 

  • 04-11-2008 3:09 PM In reply to

    • Nate
    • Top 10 Contributor
    • Joined on 08-28-2005
    • Fort Collins, CO
    • Posts 65

    Re: Strange error finding table when making call to MAPI32.dll

    Answer

    Sounds like you are using a relative path to open your database and your current path is changing because of dialog being displayed. There are several ways to deal with this such as using an absolute path or restoring the current directory when dialog windows are closed (that is a propety of openfile dialogs for example).

    Hard code a path and see what happens to confirm that is the problem.

  • 04-11-2008 3:28 PM In reply to

    Re: Strange error finding table when making call to MAPI32.dll

    Wow! That was it.

    After hard coding a path for the database files I've stopped receiving that error.

    Thanks Nate!

Page 1 of 1 (3 items)
Powered by Community Server (Commercial Edition), by Telligent Systems