.net中的Access.dao.dbengine依赖问题 [英] Access.dao.dbengine dependency issues in .net

查看:479
本文介绍了.net中的Access.dao.dbengine依赖问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Code Project,



我目前正在处理一个类库,它要求我将数据输出到Access文件(* .mdb)。我为这个* .mdb文件指定了一个模式。



我需要在新创建的数据库中指定 AllowZeroLength 属性我使用.NET对象 Access.Dao.DBEngine 执行此操作。这是我使用此代码的代码:

Hello Code Project,

I am currently working on a class library that requires me to output data into an Access file (*.mdb). I have a specified schema given to me for this *.mdb file.

I need to specify the AllowZeroLength property in my newly created database file and I do this using the .NET object Access.Dao.DBEngine. This is my code that uses this:

Private Sub SetZeroLengthFields(fullPath As String)
        Dim dbe As New Microsoft.Office.Interop.Access.Dao.DBEngine
        Dim db As Microsoft.Office.Interop.Access.Dao.Database = _
               dbe.OpenDatabase(fullPath)

        db.TableDefs("SECTIONS").Fields("LINK_ID").AllowZeroLength = True
        db.TableDefs("SECTIONS").Fields("LINK_NAME").AllowZeroLength = True
        db.TableDefs("SECTIONS").Fields("SECT_ID").AllowZeroLength = False
...



使用此对象在我的类库中有一个必需的COM引用,它使用程序集 Microsoft.Office.Interop.Access.Dao



现在,当我构建类库并在主项目中引用它时,一切都运行顺畅,并根据指定模式的需要创建访问文件,并填充数据。



当我将这个程序部署到另一台运行不同版本MSOffice的计算机上(通过使用VS2010中的安装项目)到我正在开发的版本时出现问题on(特别是:我使用的是MS Office 2010,部署的版本是MS Office 2013)。



创建对象 dbe 时我的代码我收到运行时错误:


The use of this object has a required COM reference in my class library that makes use of the assembly Microsoft.Office.Interop.Access.Dao.

Now when I build the class library and reference it in the main project everything runs smoothly and the access file is created as needed for the specified schema and the data is populated.

The issue occurs when I deploy (through use of a setup project in VS2010) this program onto another computer running a different version of MSOffice to the version I'm developing on (specifically: I'm using MS Office 2010 and the deployed version is MS Office 2013).

When creating the object dbe in my code I get a runtime error:

System.Runtime.InteropServices.COMException(0x80040154): Retrieving the COM class factory for component with CLSID{...} failed due to the following error: Class not registered 



我注意到在 C:\ Windows \assembly 下我正在使用< b> Microsoft.Office.Interop.Access.Dao 14.0.0,而已部署的计算机使用的是15.0.0。



我有办法吗?解决这个依赖问题?在Office版本不同的情况下处理这种情况的好方法是什么?



这是我的代码中唯一使用对象 Access.Dao.DBEngine 所以我现在想,我会尝试通过sql脚本找到一种指定 AllowZeroLength 的方法(如果可能的话)以防止使用这个对象。



我尝试了什么:



我试过了在我确定问题之前通过regsvr32注册我的.dll是使用Access.Dao.DBEngine对象。


I've noticed that under C:\Windows\assembly I'm using Microsoft.Office.Interop.Access.Dao 14.0.0 whereas the deployed machine is using 15.0.0.

Is there a way I can get around this dependency issue? What is a good way for dealing with such a situation when versions of Office differ?

This is the only place in my code that I make use of the object Access.Dao.DBEngine so I'm thinking for now I'll try and find a way to specify the AllowZeroLength through an sql script instead (if possible) to prevent use of this object.

What I have tried:

I've tried to register my .dll through regsvr32 before I identified the issue was with the Access.Dao.DBEngine object.

推荐答案

你为什么要使用DAO?现在它已经死了很长时间了。



Office的最后一个版本,以便公开它的功能,奇怪的是,2010年。在Office中不存在DAO支持这就是它失败的原因。


你应该一直使用OleDb和ACE引擎来访问Access数据库。
Why are you using DAO?? It's been dead for quite a long time now.

The last version of Office to expose it's functionality, oddly enough, was 2010. DAO support doesn't exist in Office 2013. That's why it fails.

You should have been using OleDb and the ACE engine for an Access database.


I我们试图通过OleDbCommand来定义允许零长度,但它似乎不是一个可访问的属性(我会在一秒钟内来到这里)。



首先,我尝试使用 ADOX.Catalog 作为快速解决方案:

I've had a look around at trying to define Allow Zero Length through an OleDbCommand but it doesn't seem to be an accessible property (I'll come to this in a second).

Firstly I tried using ADOX.Catalog as a quick solution:
Dim connstring = String.Format("{0} Data Source={1};", provider, fullPath)
Dim cat As New ADOX.Catalog
cat.ActiveConnection = connstring

cat.Tables("SECTIONS").Columns("LINK_ID").Properties( _
   "Jet OLEDB:Allow Zero Length").Value = True
cat.Tables("SECTIONS").Columns("LINK_NAME").Properties( _
   "Jet OLEDB:Allow Zero Length").Value = True
cat.Tables("SECTIONS").Columns("SECT_ID").Properties( _
   "Jet OLEDB:Allow Zero Length").Value = False
...



但是出现了设置 ADOX.Catalog.ActiveConnection 时,要知道问题。当我这样做时,我在这一行上抛出了一个错误。



我因此试图编写我给出的模式定义 DBWScript。默认为允许零长度我使用OleDbCommand中的脚本来改变我知道需要更改的列:


However there appears to be a known issue when setting ADOX.Catalog.ActiveConnection. When I did this I was thrown an error on this line.

I thus tried to script the schema definition I was given with DBWScript. As the default is Allow Zero Length I used the script in an OleDbCommand to alter columns I know needed changing as such:

Dim cmd As New OleDbCommand
Dim query = _
"ALTER TABLE [SECTIONS] DENY ZERO LENGTH [SECT_ID]; " & _
"ALTER TABLE [SECTIONS] DENY ZERO LENGTH [SECT_NAME]; " & _
...



但是当我在OleDbConnection上运行它时,这给了我一个语法错误。



根据这个帖子,不能通过Jet sql访问Allow / Deny Zero Length属性。



此时我已经放弃了。我不能完全通过.NET复制模式而不会导致COM问题。它会在我将数据交给的软件中发出一些警告,但它已经到了我认为我无法取得任何进展的地步。



再次感谢您的信息。


However this gave me a syntax error when I ran it on the OleDbConnection.

According to this post the Allow/Deny Zero Length property is not accessible through Jet sql.

At this point I've given up. I can't replicate the schema exactly through .NET without causing COM issues. It'll throw up some warnings in the software I'm handing the data over to but it's got to the point where I don't think I can make any progress on it.

Thanks again for the info.


这篇关于.net中的Access.dao.dbengine依赖问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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