Click here to Skip to main content
14,880,752 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using MS-Access 2007 as backend..

I want to create duplicate copy of database file(Means copy only structure not a data,it should be a blank database but all table structure will be same as that of original ) through vb.net.
Is it possible ?

please help me..

Thank you..
Posted

1 solution

This is probably the long way to do it. However, it's worth nothing that you can't copy an accdb without locking it, which will get you into trouble in the long run if you are in a multi user environment. Because of that I do it one of three ways:


1) Create the database and then use a function to build the tables in it. You can do something like this to create a database (note you'll need a different connection string for accdb)

C#
string cnnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + full_path_and_dbname;

object o = Activator.CreateInstance(Type.GetTypeFromProgID("ADOX.Catalog"));

System.Reflection.BindingFlags.InvokeMethod, null, o, new object[] { cnnStr });

o.GetType().InvokeMember("Create", System.Reflection.BindingFlags.InvokeMethod, null, o, new object[] { cnnStr });


then , since you created the database, You run the function/routine to build the tables.



2) Keep an empty copy of the database in a location so you can copy it to wherever you need it. This works well, if you have someplace you can store the blank copy.


3) Three is more complicated, and a bit long [so i'm not going to post the code]. You can create the empty database with the code snippet above, and then open the schema to the current database. Then you use the meta data to build the new one. It's more work, but it's a dynamic solution.. which is much better if you want to be able to change the database and not have to change any of the code.



Hope that helps some at least.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900