Create Access db Programatically

  • Thread starter Thread starter Jacob
  • Start date Start date
J

Jacob

Happy New Year!

I'm writing a program that will need to store large amounts of data from
several DataSets that I create at runtime (for information like email,
calendar, etc...). The trick is that these files will need to be created
programmatically. I think saving the DataSets into Access .mdb files is a
logical choice, but I'm unable to find any information for creating NEW
databases programmatically and I can only find information on connecting to
existing databases. So my question is:

How can I create a new database file programmatically and populate it with a
DataSet?

I've read the article: HOW TO: Create an Access Database Using ADOX and
Visual C# .NET (http://support.microsoft.com/?id=317881). With that I can
create a new empty .mdb file and creating the DataSet is no problem, but
that's as far as I've got.

If someone could suggest a solution, or an alternative I would appreciate
it.

Thanks,
Jacob
 
Jacob said:
How can I create a new database file programmatically and populate it with
a DataSet?

What's wrong with exportin/importing using XML?
I've read the article: HOW TO: Create an Access Database Using ADOX and
Visual C# .NET (http://support.microsoft.com/?id=317881). With that I can
create a new empty .mdb file and creating the DataSet is no problem, but
that's as far as I've got.

Once you've got the database constructed, use an OleDbAdapter to read and
write information from/to the database. Better yet, if you already know the
structure of your database, create it now and simply ship it with your app.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
Will the structures of the databases always be the same? Do you know the
structure ahead of time? If so, then you might just create some empty
database templates that you can simply copy to the destination. Then you
can connect and load the data.
 
It wouldn't be practical for me to store information in XML. These
databases will be VERY large. I've run some tests and found that if I save
in XML, the file sizes would be several dozen megabytes large. In an Access
db, they would be almost 1/5 - 1/6 the size.

You're right, I can create the database and ship it with the app, but was
hoping not to have to.

Thanks,
Jacob
 
I was hoping not to have to do that. I always worry that if the file
becomes corrupted or the user does something stupid, that the application
would fail. But if I could create the db programtically, I could construct
a new one on the fly.

Jacob
 
Most programs out their ship with satellite files. If the user chooses to
modify these files outside of the application's control and in undocumented
ways, there is really not anything you can do about that.

But, an alternative might be to embed a pre-fabricated database as a
resource in your application. That way it is actually compiled as part of
your executable. Then you would simply stream the binary data back to disk
when needed.
 
Back
Top