如何创建重复的数据库(accdb)副本 [英] How to create duplicate Database(accdb) copy

查看:105
本文介绍了如何创建重复的数据库(accdb)副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用MS-Access 2007作为后端..

我想通过vb.net创建数据库文件的重复副本(意味着仅复制结构而不是数据,它应该是空白数据库,但所有表结构都将与原始表相同).
有可能吗?

请帮帮我..

谢谢..

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..

推荐答案

这可能是很长的路要走.但是,如果不锁定它就无法复制accdb,这毫无价值,如果您处于多用户环境中,从长远来看,这将给您带来麻烦.因此,我采用以下三种方式之一进行操作:


1)创建数据库,然后使用一个函数在其中建立表.您可以执行类似的操作来创建数据库(请注意,accdb需要一个不同的连接字符串)

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)

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 });



然后,由于创建了数据库,因此您可以运行函数/例程来构建表.



2)将数据库的空副本保留在某个位置,以便可以将其复制到所需的任何位置.这很好用,如果有地方可以存储空白副本.


3)三个比较复杂,而且有点长[所以我不打算发布代码].您可以使用上面的代码段创建空数据库,然后将架构打开到当前数据库.然后,您可以使用元数据来构建新数据.它的工作量更大,但是它是一个动态的解决方案.如果您希望能够更改数据库而不必更改任何代码,那就更好了.



希望至少能有所帮助.



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.


这篇关于如何创建重复的数据库(accdb)副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆