embeding a databse inside my application


for demo purposes i might need a sql or access database to be embedded inside my application and installed with it and the application will connect to it no matter what the installation path was how to do that ?
Who is Participating?
VBRocksConnect With a Mentor Commented:
Here's a VS 2005 Demo I put together for you:


Only things to point out is to add the database to the project:

    Project menu | Add Existing Item...  (navigate to, and select your database)
    In Solution Explorer, right-click on the database, set:
        Build Action = Embeded Resource
        Copy To Output Directory = Do Not Copy

Using a access database, you can install the mdb file in the same path as your exe file.
In your application, connect to your database using a relative path (only the database name) like this:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=My_DB.mdb;Persist Security Info=False"
SQL Server Compact 3.5 may be a good option. It is installed in VS 2008 and can even be used to demo web apps.

Another option is to use an XML file. DataSets can be converted to XML with the .WriteXml method. use .WriteXmlSchema to store keys, relationships, etc. After executiing a .ReadXml, a DataSet is ready to go!
You can actually embed the access database into your executable, then when the executable is run, "extract" the database from the executable, write it out to the user's application data directory, then hook up to it from there.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.