如何从流中读取 Access 文件 (.accdb)? [英] How can I read an Access file (.accdb) from a stream?
问题描述
我问了两个类似的问题:
I asked two similar questions:
通过 OpenXML 读取 Microsoft Access 文件 (.accdb)SDK
我所有的尝试都是从流中读取 Access 文件 (.accdb).我尝试使用 OLEDB 和 OpenXML SDK,但似乎它们都无法访问流.
All of my attempts have been to have read an Access file (.accdb) from a stream. I've tried to use OLEDB and OpenXML SDK, but it seems none of them are able to access a stream.
那么,有人知道吗?或者有没有其他解决方案可以从流中读取 Access 文件?
So, does anyone know about this? Or is there any other solution to read an Access file from a stream?
推荐答案
在幕后访问数据库严重依赖文件使用.与 SQLLite 等内存数据库不同,Access Db 需要一个文件.因此,您必须使用 OLEDB、OPENXML 或通过对象模型来处理文件.
Under the hood Access Databases rely heavily on file usage. Unlike in-memory database such as SQLLite, Access Db's need a file. Hence you'll have to work with the file using OLEDB, OPENXML or via the Object Model.
自 .Net 4. Streams 有一个 CopyTo 方法,您可以使用它将流转换为临时 accdb 文件.
Since .Net 4. Streams have a CopyTo method you can use to convert the stream into a temporary accdb file.
string tempFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\temp.accdb";
using (var fileStream = File.Create(tempFilePath)
{
accDbStream.InputStream.CopyTo(fileStream);
}
这篇关于如何从流中读取 Access 文件 (.accdb)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!