Hi Again All,

I have a Datasource which I query, works fine but when I package the application it can't find the datasource (which is an mdb file) how do I set the datasource to always look in the application path.

I have tried str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= App.Path + \REPRINT.MDB;Persist Security Info=False" but it doesn't like this either. As always any help is appreciated.

Dani AI

Generated

As demonstrated for , the reliable fix is to build the database file path at runtime from the application's folder instead of hard‑coding a filename. That resolves the “works in dev but not when packaged” symptom because the packaged app often runs from a different working folder or the MDB never got included in the output.

Example (VB.NET) — build a path that always points next to the executable:

Dim dbPath As String = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "REPRINT.MDB")

If the app needs to write to the database, keeping the MDB in Program Files will fail on modern Windows due to UAC. A common pattern is to copy the shipped MDB to a writable per‑user location on first run and use that copy:

Dim destDir = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MyCompany", "MyApp")
If Not System.IO.Directory.Exists(destDir) Then System.IO.Directory.CreateDirectory(destDir)
Dim destFile = System.IO.Path.Combine(destDir, "REPRINT.MDB")
If Not System.IO.File.Exists(destFile) Then System.IO.File.Copy(dbPath, destFile)
' use destFile as the database path for connections

Additional deployment notes: add the MDB to the project and set its file property to Content / Copy to Output Directory (Copy if newer) so it appears beside the exe after build or include it in the installer. On 64‑bit Windows the old Jet provider runs only in 32‑bit processes — set the project’s target CPU to x86 (Project → Properties → Compile → Advanced Compile Options → Target CPU) or use the ACE driver and install the matching Access Database Engine. For troubleshooting, log the computed full path the app is using so missing‑file problems are obvious. This also answers : replace any hard‑coded datasource path with a runtime path builder and ensure the MDB is deployed with the app.

Recommended Answers

All 3 Replies

Hi
Try this str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\REPRINT.MDB;Persist Security Info=False"

Excellent ! Thank you .

i also face this problem in Visual Studio 2010 express. The problem which code should be replaced with your code? in order to prevent program defining data source file path by itself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.