简体   繁体   English

在32位或64位环境中创建Access数据库

[英]Creating an Access Database in 32-bit or 64-bit Environments

I don't believe there's a solution to my problem, but I thought I'd ask just in case I missed or misunderstood some aspect of it: 我不认为我的问题有解决方案,但是我想我想问一下,以防万一我遗漏或误解了它的某些方面:

  1. I have a C# program that creates and writes to an Access Database. 我有一个C#程序,用于创建和写入Access数据库。 More specifically, a C# library that will be part of a suite of applications. 更具体地说,C#库将成为一组应用程序的一部分。
  2. This library cannot be targeted at 32 or 64 bit specifically because that would mean all the programs in the suite would have to be targeted specifically (can't load the dll into a 64 bit operating space if it's built for 32 bit, or vice versa. I think?). 该库不能专门针对32位或64位,因为这意味着该套件中的所有程序都必须专门针对(如果dll是针对32位构建的,则无法将dll加载到64位操作空间中,反之亦然。 我认为?)。
  3. I believe the "2010 Office System Driver Connectivity Components" allow me to connect and write to an Access database (.mdb) from a 64 bit environment. 我相信“ 2010 Office System驱动程序连接组件”使我可以从64位环境连接并写入Access数据库(.mdb)。 However, one of the other requirements would be to not have an outside dependency on various Microsoft Access redistributable versions (we had issues with an Access application in the past). 但是,其他要求之一是不要对各种Microsoft Access可再发行版本具有外部依赖性(过去我们在Access应用程序方面遇到问题)。

Therefore, what I'm really looking for is some OS-independent (and 32/64bit independent) way to create and write to an Access database from C#. 因此,我真正要寻找的是某种独立于OS(且独立于32/64位)的方法,用于从C#创建和写入Access数据库。 Does such a thing exist, or are my options pretty much as outlined above? 这样的事情是否存在,或者我的选择是否大致如上所述?

One thought was that we could pull out the dlls we depend on from the connectivity components, but I'm fairly certain those are targeted to either a 32bit or 64bit environment, so it would fail when we tried to run on the non-target platform. 一种想法是,我们可以从连接组件中提取依赖的dll,但是我可以确定这些DLL是针对32位或64位环境的,因此当我们尝试在非目标平台上运行时,它将失败。 。 Or would they run like a C# program targeted to "Any" and just adjust depending on the environment? 还是它们像针对“任何”的C#程序一样运行,并根据环境进行调整?

In a prior application I worked on, there was the need to export data to an Access database. 在我研究的先前应用程序中,需要将数据导出到Access数据库。 However, if Access wasn't installed, no direct way to "Create" an empty database. 但是,如果未安装Access,则没有直接“创建”空数据库的方法。 Since you can't connect to a database that doesn't exist, what I did was to create an empty database, embedded the file itself as a resource to the application. 由于您无法连接到不存在的数据库,因此我要做的是创建一个空数据库,将文件本身作为应用程序的资源嵌入。 Then, when I needed to create a new "access database", I would stream read it, and write the empty database structure out to wherever it needed to go with whatever file name it needed. 然后,当我需要创建一个新的“访问数据库”时,我将对其进行流式读取,并将空的数据库结构写到需要的位置,并带有所需的任何文件名。 Since the database was already created in 32-bit environment, it didn't have problems for subsequent connection to it... but that too was before 64bit machines were becoming more common. 由于该数据库已经在32位环境中创建,因此它随后的连接没有问题...但是在64位计算机变得越来越普遍之前也是如此。

Hope this helps as an option / solution for you. 希望这对您有所帮助。

Actually, if you write an application - you can just force-target it at 32bit and not worry at all. 实际上,如果您编写应用程序,则可以只将其强制定位为32位,而不必担心。 When started in a 64 bit environment - it will "just run". 在64位环境中启动时-它会“运行”。

If you're writing a dll/assembly, that will be referenced by an app, and you know that this app will be compiled as "Any CPU" or "64 bit", then you're out of luck, and this answer won't help you, probably :D 如果您正在编写一个dll /程序集,它将被某个应用程序引用,并且您知道该应用程序将被编译为“任何CPU”或“ 64位”,那么您就不走运了,这个答案就很成功了。帮不了你,也许:D

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

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