After deploying my project, I tried to install it on other pc , it installs well but whenever i run the .exe application my database file which is MS Access cannot be found. Well obviously the path is the problem.

How would i make my path flexible and so that whenever i install it to other pc, my database will already be found. And also how can i include the database file inside the installer.

Really need your help!...Simple codes will be great. I'm just a beginner.

This is the code i used for the path

Sub ConnectRecord(ByVal sql As String)
    Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & GetMyMDBPath() & "TanProj.MDB"
    Dim dataAdapter As New _
    OleDb.OleDbDataAdapter(sql, connStr)
    dataAdapter.Fill(dt)
    dataAdapter.Dispose()
  End Sub

  Function GetMyMDBPath()

    GetMyMDBPath = "C:\Users\user\Desktop\"
  End Function

Hi SaberExcalibur,
I had this sort of problem and also found that the database wouldnt update properly.
The database update problem resulted from vb.net creating an additional copy of the database, unbeknown to me, in the debug subfolder on which all the updates were being made. Check your assemblies (cant remember exactly which one) and make sure local property is false for the mdb.

Also I created some code within the 1st form when it loaded which checked the current path of the deployed solution and set the path to the database with the correct path in the C:\program files\xxx\yyy\mydb.mdb folder. My db was in the deployed solution folder.
Obviously if your database is hard coded to a network path then this should still be ok.

Do a search on your development PC and check there are no other local copies of the database. I can provide some code/more detail etc in the next day or 2 if you need it but havent got access to it right now.
regards
Waldek

Though you havent replied, check assembly for your database, the Copy local property should be DO NOT COPT.

To deploy you need to create a setup project within your solution and add the database to it using the File System editor.
thanks

If your database will always be in the same directory as your application you can use reflection to get the path, like this:

Private Function GetDataBaseFilePath() As String
        Dim path As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location())
        path = System.IO.Path.Combine(path, DataBaseFileName)
        Return path
    End Function

from DonPawpaw[/COLOR

' in order to make this process work correctly
1. make sure your access database in the Debug folder in your applicaion folder
'use application.starupPath to dynamically locate your database in your insallation folder (ie.folder where you installed the application)

Sub ConnectRecord(ByVal sql As String)
    Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & APPLICATION.STARUPPATH & "TanProj.MDB"
    Dim dataAdapter As New _
    OleDb.OleDbDataAdapter(sql, connStr)
    dataAdapter.Fill(dt)
    dataAdapter.Dispose()
  End Sub

  Function GetMyMDBPath()

hope this help by donpawpaw Blay

This article has been dead for over six months. Start a new discussion instead.