简体   繁体   English

ADOX不能用在VS2010中?

[英]ADOX can't be used in VS2010?

I want to use ADOX to create a database in VS2010 but on using 'ADOX.catalogClass' i get the unusual error: Interop type 'ADOX.CatalogClass' cannot be embedded. 我想使用ADOX在VS2010中创建一个数据库但是在使用'ADOX.catalogClass'时我得到了一个不寻常的错误:无法嵌入Interop类型'ADOX.CatalogClass'。 Use the applicable interface instead. 请改用适用的界面。 Actually the specific line being marked as an error is: ADOX.CatalogClass cat = new ADOX.CatalogClass(); 实际上,标记为错误的特定行是: ADOX.CatalogClass cat = new ADOX.CatalogClass();

Does ADOX not work for VS2010? ADOX不能用于VS2010吗? How can i solve this? 我怎么解决这个问题? Thanks 谢谢

You have the "Embed interop types" option set to True on the reference. 您在引用上将“嵌入互操作类型”选项设置为True。 Very nice feature, but it doesn't support using the XxxClass wrapper directly. 非常好的功能,但它不支持直接使用XxxClass包装器。 Unintuitive, but you can create an instance of the COM interface with the new operator. 不直观,但您可以使用new运算符创建COM接口的实例。 Change your code to this to get rid of the error: 将您的代码更改为此以消除错误:

   ADOX.Catalog cat = new ADOX.Catalog();

I used ADOX in VS2010 with ADOX.Catalog, not CatalogClass. 我在VS2010中使用ADOX与ADOX.Catalog,而不是CatalogClass。 Here's an example of where I use it: 这是我使用它的一个例子:

private void CreateAndExportLegacyFile(string exportFilePath)
{
    var connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;";
    connectionString += "Data Source=" + exportFilePath + ";Jet OLEDB:Engine Type=5";

    var catalog = new Catalog();
    catalog.Create(connectionString);

    var table = new Table { Name = "Main" };

    #region Column mapping
    table.Columns.Append("ID", DataTypeEnum.adVarWChar, 50);
    // Snipped rest of them
    #endregion

    foreach (Column column in table.Columns)
    {
        if (column.Name != "ID")
        {
            column.Attributes = ColumnAttributesEnum.adColNullable;
        }
    }

    catalog.Tables.Append(table);

    Marshal.FinalReleaseComObject(table);
    Marshal.FinalReleaseComObject(catalog.Tables);
    Marshal.FinalReleaseComObject(catalog.ActiveConnection);
    Marshal.FinalReleaseComObject(catalog);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM