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!

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.