Access数据库中提取源代码

Access数据库中提取源代码

本文介绍了从MS Access数据库中提取源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Access数据库,我想提取源代码,所以我可以把它放到源代码控制。

I have an Access DB that I would like to extract the source code from so I can put it into Source control.

我试图提取使用主互操作程序集(PIA)的数据,但我得到,因为它是不是捡了所有模块和形式的问题。

I have tried to extract the data using the Primary Interop Assemblies(PIA), but I am getting issues as it is not picking up all of the modules and forms.

有140窗体和模块的代码(不要问,这是一个遗留系统我继承),但PIA代码只拿起其中的91。

There are 140 Forms and Modules in the code(Don't ask, it's a legacy system I have inherited) but the PIA code is only picking up 91 of them.

下面是我使用的代码。

Here is the code I am using.

using System;
using Microsoft.Office.Interop.Access;

namespace GetAccesSourceFiles
{
    class Program
    {
        static void Main(string[] args)
        {
            ApplicationClass appClass = new ApplicationClass();
            try
            {
                appClass.OpenCurrentDatabase("C:\\svn\\projects\\db.mdb",false,"");

                Console.WriteLine(appClass.Version);
                Console.WriteLine(appClass.Modules.Count.ToString());
                Console.WriteLine(appClass.Modules.Parent.ToString());

                int NumOfLines = 0;
                for (int i = 0; i < appClass.Modules.Count; i++)
                {
                    Console.WriteLine(appClass.Modules[i].Name + " : " + appClass.Modules[i].CountOfLines);
                    NumOfLines += appClass.Modules[i].CountOfLines;
                }

                Console.WriteLine("Number of Lines : " + NumOfLines);
                Console.ReadKey();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message + "\r\n" +ex.StackTrace);
            }
            finally
            {
                appClass.CloseCurrentDatabase();
                appClass.Quit(AcQuitOption.acQuitSaveNone);
            }

        }
    }
}

这是什么代码可能丢失有什么建议? ?或者在产品/工具,在那里,会为我做到这一点。

Any suggestions on what that code might be missing? or on a product/tool out there that will do this for me?

编辑:
我还要提到的是这需要脚本盘,集成VSS是不是一种选择,因为我们的源系统SVN。谢谢你。

I should also mention that this needs to script to disk, integration with VSS is not an option as our source system is SVN. Thanks.

推荐答案

您可以使用无证的 Application.SaveAsText Application.LoadFromText 的功能。 SaveAsText作用于模块,窗体和报表;当您保存窗体或报表,文本,它的模块代码将出现在生成的文本文件的底部。

You could use the undocumented Application.SaveAsText and Application.LoadFromText functions. SaveAsText works on modules, forms, and reports; and when you save a form or report as text, its module code will appear at the bottom of the resulting text file.

您可以编写一个程序,将保存所有的在Access MDB(或ADP)作为文本的非数据对象,把它放在一个模块中,而只是保持该模块中的Access数据库的开发版本。然后,你可以运行程序,并在VSS转储检查代码。

You could write a routine that would save all of the non-data objects in your Access MDB (or ADP) as text, put it in a module, and just keep that module in a development version of your Access DB. Then you could run the routine and check in the dumped code in VSS.

这也许并不像米奇小麦所述的Visual SourceSafe方法一样优雅,但要看是什么你想与源代码做。我倾向于挂到MDB的多个版本,并使用此方法,使用比较工具,它们之间进行比较的源代码,如的WinMerge。这是很好的移植开发分支之间的功能。

It's probably not as elegant as the Visual SourceSafe method described by Mitch Wheat, but that depends on what you want to do with the source code. I tend to hang onto multiple versions of MDB's, and use this method to compare source code between them using diff tools such as WinMerge. It's good for porting functionality between branches of development.

这也是很好的定位到字段或控件的所有引用无论他们在哪里被发现。查看访问对象作为文本的定义使得寻找这些引用死的简单。

It's also good for locating all references to fields or controls wherever they may be found. Viewing Access objects as textual definitions makes finding these references dead simple.

这篇关于从MS Access数据库中提取源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 00:26