Hey All!

I have created a database application which read and write data in Ms Access. It works well on my computer but when i try to install the same application via installer package to another computer, and run it, it gives me error that i dont have the database. So i want to know if there is any method so that one can create MS Access database from the application rather than to create manually. All the table in database must be created via the application when it installs.

thanks, good day!

Dani AI

Generated

Quick recap for the thread: ran into the classic “database not found / file previously opened” on other machines; ’s diagnosis (that the app was trying to use a protected install folder) was the right lead and should be treated as the first fix. Below are focused, practical notes to make installer-created databases reliable across targets, plus common traps that cause the “file already open” exceptions.

If the target format must be Access 2007+ (.accdb) the Access Database Engine (ACE) / Access runtime must be available on the target machine (ACE provides the Microsoft.ACE.OLEDB provider used for .accdb). Programmatic creation is possible (ADOX/DAO) when ACE is installed, but the most robust deployment is to ship a blank .accdb template with the installer and copy it to the final writable location at install or first run, then run schema updates against that copy. (support.microsoft.com)

Pay attention to bitness. ACE/Office components come in 32‑ and 64‑bit builds; mismatched bitness between app and provider leads to “provider not registered” errors or failed installs. For broad compatibility many desktop apps target x86 or ensure the installer installs the matching ACE/runtime and documents that requirement. (learn.microsoft.com)

Practical checklist (most common, actionable items):

  • Create or copy the DB during installer execution (installer runs elevated), placing it either in a per‑user AppData folder or in an application subfolder under ProgramData — if using ProgramData the installer must create the subfolder and set ACLs so non‑admin users can write. (stackoverflow.com)
  • If the app creates the DB at runtime, ensure every connection/command/recordset is closed and all COM objects are explicitly released (use Marshal.ReleaseComObject/FinalReleaseComObject and, when appropriate, a coordinated GC.Collect/WaitForPendingFinalizers) to avoid lingering locks. (learn.microsoft.com)
  • Check for external lockers (antivirus, backup, orphaned process). If creation still fails, log the exact path and exception, try creating a uniquely named file, then rename — that isolates permission vs lock issues.

TL;DR — shipping a blank .accdb and copying it into a properly permissioned folder at install time is the simplest, most dependable path; ACE + ADOX/DAO is available when the runtime is installed and the app/provider bitness is handled correctly. (support.microsoft.com)

Recommended Answers

All 5 Replies

Often when you include a database in your applicaiton, it uses the |DataDirectory| path to reference the conneciton. You can change the path by setting the AppDomain.SetData method. More then likely the database is being installed to the target system, but the applicaiton does not have the user rights to write to the application folder.

One solution is to change the path ofthe database to the Current User repository (usually Users/AppData folder) or to the Program repository (C:\ProgramData) where is can be accessed by any user on the system. These folders allow you to read/write to a database.

Another solution is to build the database through the application using T-SQL. This will be tricky if you are unfimiliar with T-SQL's syntax.

I personally would choose the first solution. That way you can get your app to market and not spend all your time with statements to build the database through the application.

i have tried this code, but its giving an exception that the file is previously opened. Believe me there is no file present on my computer having this name.

Dim cat As ADOX.Catalog = New ADOX.Catalog()
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Users\AccessDB.mdb;Jet OLEDB:Engine Type=5")

The error is a generic error that means it cannot open the database. The directory you gave is not a writable directory. Try this:

 Dim cat As New ADOX.Catalog()
            cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" &
                       "Data Source=" & My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\AccessDB.mdb")

It willl create an Access.mbd file in the user's MyDirectory folder. Notice how I used My.Computer.FileSystem.SpecialDirectories.MyDocuments property?

My Documents has write permissions without Administrative privileges.

Thanks alot Maligui! this worked! Thank you so much. One thing more that it creates the database of 2002-2003 format, cant it create of 2007 or 2011?

Once again thanks alot.

I believe it depends on the version of the COM component:

Microsft ADO Ext. x.x for DLL and Security.

I think version 6.0 willl make 2007-2009 version of access.

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.