I am experiencing the strangest behavior when trying to test a project on a machine other than my development machine. Everything works fine on the development machine, but when deploying the program, I receive "Error on opening DbConnection." with the InnerException "Unable to open database file."
Basically, I have an empty database (the schema only) in the same folder as the exe file, and like I said, everything works fine on the development machine. I am using LinqConnect to query the SQLite database. Here is the method that is having the error (also receive the same error with any methods that are accessing the database).
private void LoadAccountsFromDatabase()
{
var accounts = new ObservableCollection<Account>();
var connectionString =
string.Format("Data Source='{0}';Version=3;Default Command Timeout=10000;", UserPreferences.DatabasePath);
AccountsGrid.CommitEdit();
AccountsGrid.SelectedItem = null;
MessageBox.Show(connectionString);
try
{
using (var db = new MainDataContext(connectionString))
{
MessageBox.Show("step 4.5");
var query = from a in db.Accounts
where a.Inactive == 0 || a.Inactive == null || ShowInactiveCheckBox.IsChecked == true
orderby a.AccountName, a.AccountNickname
select a;
try
{
MessageBox.Show("step 4.6");
if (query.Any())
{
MessageBox.Show("step 4.61");
foreach (var item in query)
{
MessageBox.Show("step 4.65");
accounts.Add(item);
}
}
MessageBox.Show("step 4.7");
AccountsGrid.ItemsSource = accounts;
MessageBox.Show("step 4.8");
}
catch (Exception e)
{
MessageBox.Show("accounts add " + e.Message);
if (e.InnerException != null)
{
MessageBox.Show(e.InnerException.Message);
}
}
}
}
catch (Exception e)
{
MessageBox.Show("load accounts " + e.Message);
}
}
I get the "step 4.6" message, and then the exception. I don't see "step 4.61" so it appears that the error is on the line if (query.Any())
which is what is bizarre, as the underlying tables are empty, so there are no results. Does anyone have any ideas what could be the issue here? I do have the LinqConnect DLL files deploying with the exe, as well as the sqlite3.dll, so that shouldn't be the issue.