从MS Access数据库
提取源代码我有一个Access数据库,我想提取源代码,所以我可以把它放到源代码控制。从MS Access数据库
我试图提取使用主互操作程序集(PIA)的数据,但我得到,因为它是不拾取所有模块和形式的问题。
有140个窗体和模块的代码(不要问,这是一个遗留系统我继承),但PIA代码只拿起他们的91。
这是我使用的代码。
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);
}
}
}
}
关于该代码可能丢失的任何建议?或在那里的产品/工具会为我做这个?
编辑: 我还应该提到,这需要脚本到磁盘,因为我们的源系统是SVN,因此与VSS的集成不是一种选择。谢谢。
有一个更好的方法。您可以使用的Visual SourceSafe(可能还有其他SCCS)版本控制代码和对象到位:看到这个MSDN article
嗨米奇, 对不起,我应该提到这一点。 我们的源代码控制是SVN内部,我已经看过VSS工具,但它确实需要脚本化到一个文件夹,以便我可以将它提交给SVN。 感谢您的答复,但:-) – evilhomer 2008-10-13 14:46:20
作为最后的手段,你可以把所有的Access开发到VSS吗? – 2008-10-13 14:48:46
这可能会帮助:
Sub AllCodeToDesktop()
'The reference for the FileSystemObject Object is Windows Script Host Object Model
'but it not necessary to add the reference for this procedure.
Dim fs As Object
Dim f As Object
Dim strMod As String
Dim mdl As Object
Dim i As Integer
Set fs = CreateObject("Scripting.FileSystemObject")
'Set up the file.
Set f = fs.CreateTextFile(SpFolder("Desktop") & "\" _
& Replace(CurrentProject.Name, ".", "") & ".txt")
'For each component in the project ...
For Each mdl In VBE.ActiveVBProject.VBComponents
'using the count of lines ...
i = VBE.ActiveVBProject.VBComponents(mdl.Name).CodeModule.CountOfLines
'put the code in a string ...
If VBE.ActiveVBProject.VBComponents(mdl.Name).codemodule.CountOfLines > 0 Then
strMod = VBE.ActiveVBProject.VBComponents(mdl.Name).codemodule.Lines(1, i)
End If
'and then write it to a file, first marking the start with
'some equal signs and the component name.
f.writeline String(15, "=") & vbCrLf & mdl.Name _
& vbCrLf & String(15, "=") & vbCrLf & strMod
Next
'Close eveything
f.Close
Set fs = Nothing
End Sub
Function SpFolder(SpName As String)
'Special folders
SpFolder = CreateObject("WScript.Shell").SpecialFolders(SpName)
End Function
来源:http://wiki.lessthandot.com/index.php/Code_and_Code_Windows
你能我们E中的无证Application.SaveAsText和Application.LoadFromText功能。 SaveAsText适用于模块,表单和报告;当您将表单或报告另存为文本时,其模块代码将显示在生成的文本文件的底部。
您可以编写一个例程,将所有非数据对象作为文本保存在Access MDB(或ADP)中,放入模块中,并将该模块保存在Access数据库的开发版本中。然后,您可以运行该例程并检查VSS中的转储代码。
它可能不是由米奇小麦描述的Visual SourceSafe方法优雅,但取决于你想要的源代码做什么。我倾向于使用多种版本的MDB,并使用此方法使用比较工具(如WinMerge)比较它们之间的源代码。在开发分支之间移植功能是很好的。
这也是很好的定位到字段或控件的所有引用无论他们在哪里可以找到。将Access对象看作文本定义使查找这些引用变得非常简单。
另请参见http://stackoverflow.com/questions/247292/working-with-multiple-programmers-on-ms-access – Yarik 2008-11-03 05:29:27