2

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.

4
  • As it cannot connect to the DB, then I would guess it is an issue with the connection string. So you should post that in the question. Commented Jan 17, 2022 at 11:36
  • Can you share with us publish config file of your project ? Commented Jan 17, 2022 at 11:40
  • @jason.kaisersmith I added my connectionString Commented Jan 17, 2022 at 12:10
  • @Roa which config file you mean? Commented Jan 17, 2022 at 12:11

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I have tried using relative path but no success. Also I pasted db file in My documents folder so I could easily access it. In the debug mode it works but when I publish it it falls
How do you publish the add-in? Do you use a ClickOnce installer? Where do you install the add-in?
Yes by using ClickOnce installer. I have installed on C disk program files folder. But I also used Visual Studio Installer. But on other computers it did not run on others
It seems you have mixed the installation. You need to use a single installer - ClickOnce or MSI (not two together).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.