我嘗試在.NET 4.0框架中編譯Xsd2Db解決方案。我想補充爲「Microsoft ADO分機6.0 DDL和安全性。」的引用,並以這種方式使用它 -.NET 4.0應用程序使用Microsoft ADO Ext。 6.0 DDL和安全
using System;
using System.IO;
using ADOX;
namespace Xsd2Db.Data
{
/// <summary>
/// Summary description for JetDataSchemaAdapter.
/// </summary>
public sealed class JetDataSchemaAdapter : AdoxDataSchemaAdapter
{
/// <summary>
///
/// </summary>
internal const string Extension = ".mdb";
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
internal static string GetPath(string name)
{
return Path.GetFullPath(
Path.ChangeExtension(name, Extension));
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
internal static string GetConnectionString(string name)
{
return String.Format(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Engine Type=5;",
GetPath(name));
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
protected override void DeleteCatalog(string name)
{
File.Delete(GetPath(name));
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
protected override void CreateCatalog(string name)
{
// Force the run-time to let go of the file! Otherwise,
// cleanup and other operations might fail because the file
// will still be in use.
Catalog catalog = new CatalogClass();
catalog.Create(GetConnectionString(name));
catalog.ActiveConnection = null;
catalog = null;
GC.Collect();
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
protected override Catalog OpenCatalog(string name)
{
Catalog catalog = new CatalogClass();
catalog.let_ActiveConnection(GetConnectionString(name));
return catalog;
}
}
}
現在我在編譯過程中有一個錯誤 - 「類型‘ADOX.CatalogClass’沒有構造函數定義」。
點擊鏈接錯誤使我的元數據 -
#region Assembly Interop.ADOX.dll, v4.0.30319
// C:\xsd\xsd2db\xsd2db\Common\DataSchemaAdapter\obj\Debug\Interop.ADOX.dll
#endregion
using System;
using System.Reflection;
using System.Runtime.InteropServices;
namespace ADOX {
[Guid("00000602-0000-0010-8000-00AA006D2EA4")]
[ClassInterface(0)]
[TypeLibType(2)]
public class CatalogClass : _Catalog, Catalog {
public CatalogClass();
[DispId(1)]
public virtual dynamic ActiveConnection { get; set; }
[DispId(4)]
public virtual Groups Groups { get; }
[DispId(2)]
public virtual Procedures Procedures { get; }
[DispId(0)]
public virtual Tables Tables { get; }
[DispId(5)]
public virtual Users Users { get; }
[DispId(3)]
public virtual Views Views { get; }
[DispId(6)]
public virtual dynamic Create(string ConnectString);
[DispId(7)]
public virtual string GetObjectOwner(string ObjectName, ObjectTypeEnum ObjectType, object ObjectTypeId = Type.Missing);
[DispId(1)]
public virtual void let_ActiveConnection(object pVal);
[DispId(8)]
public virtual void SetObjectOwner(string ObjectName, ObjectTypeEnum ObjectType, string UserName, object ObjectTypeId = Type.Missing);
}
}
我們可以看到公共CatalogClass();但不是構造函數。
我相信在.NET 1.x這工作。但爲什麼.NET 4.0有這個問題?任何人都知道這一點,什麼是處理這個問題的最好方法?
謝謝!