Cannot add sqlite db file to Word adding deployment

Viewed 82

I developed C# Word add-in which populates some data from database file. It is working fine while I am running through Visual studio running. But if I publish it cannot connect to database.

Here is how I get data from database:

SQLiteConnection con = new SQLiteConnection(ThisAddIn.connectionString);
            con.Open();

            var command = con.CreateCommand();
            command.CommandText =
            @"
                SELECT *
                FROM JK
                WHERE article_number = $article_number
            ";
            command.Parameters.AddWithValue("$article_number", textFromDoc);

            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    var title = reader.GetString(2);
                    var article = reader.GetString(3);

                    ResultForm resultForm = new ResultForm();
                    resultForm.setArticle(title, article);
                    resultForm.ShowDialog();
                }
            }

public static string connectionString = @"Data Source=E:\projects\c#\TBPWordAddin\WordAddIn1\codexes.db";

Am I doing something wrong or do I need to include file in another way? Any help will be appreciated.

Also I tried publishing using Visual studio installer and it connected to database but the add in didnot lounched on other computers.

1 Answers

The connection string contains an absolute path which can be changed after publishing an application. I'd suggest using a relative path instead - in that case you will be able to find the Db easily. You may check out the following threads for more information on such kind of issues:

But if I publish it cannot connect to database.

Make sure the Db path (see the connection string) corresponds to the hardcoded value in the application used.

Related