Search code examples
vb.netsqlitedatabase-connectionsetup-projectvb.net-2010

Program connects after install to an unknown(?) sqlite database


I have a strange problem using vb.net (vs2010) and SQLite database: I made an install package with Setup and Deployment project, everything seems to be working fine. My SQLite databse installs under CommonApplicationData folder and the software under ProgramFiles\ProductName. In the setup project I set a custom action, the user have a choice to run software after install: /StartApp="[CHECK]"

Private Sub MyInstaller_Committed(ByVal sender As Object, ByVal e As InstallEventArgs)
Dim productName As String = Context.Parameters("ProductName")
StartAfterInstall = Me.Context.Parameters.Item("StartApp")
If StartAfterInstall = "1" Then
    Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
    Shell(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\FB.exe")
End If
End Sub

In ApplicationEvents.vb I set at StartUp:

    AppDomain.CurrentDomain.SetData("DataDirectory", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData))

And here comes the strange behaviour: if the user starts application after install, the program connects to another(?) database, not to installed under CommonApplicationData. If the user inserts data, seems everything working fine. After closing the application and starting new from the desktop/programfiles/users program menu connects the program to the database installed under CommonApplicationData, but he can't see the changes he made launching application after installation. So starting program from desktop/programfiles/users program menu => everything fine, but the first (automatic) start after install is a problem. I can't find out what happens, any ideas?


Solution

  • Has your Installation Administrator-Privileges? If yes, the following probably happens:

    1. you are writing to ProgramFiles. Windows redirects this to the administrator %appdata%\roaming folder because writing to ProgramFiles is considered bad.
    2. It goes to the administrator account because the installation had administrator-privileges.
    3. When you start your program from the user account, the user-specific %appdata% Folder is used, which is empty.

    Do solve that problem:

    1. do not launch your program from the installer.
    2. Create a directory for your program in %appdata% and usw it.