简体   繁体   English

如何使用 VFP OLE DB 提供程序关闭表

[英]How to close a table with the VFP OLE DB Provider

I'm writing some software in C# that will perform queries on Visual FoxPro datafiles over time.我正在 C# 中编写一些软件,这些软件将随着时间的推移对 Visual FoxPro 数据文件执行查询。 I need to be able to close tables, especially those that are opened exclusively ("Mode=Share Exclusive" in the Connection String), but the only way I can seem to do that is by closing the entire OleDbConnection.我需要能够关闭表,尤其是那些以独占方式打开的表(连接字符串中的“模式=共享独占”),但我似乎可以这样做的唯一方法是关闭整个 OleDbConnection。

The VFP OLE DB Provider supports some syntax from VFP itself, but commands that would close a table in standard VFP, such as USE, either do not work, or throw an exception (I can't recall which command threw an exception at the moment). VFP OLE DB Provider 支持 VFP 本身的一些语法,但是会在标准 VFP 中关闭表的命令,例如 USE,要么不起作用,要么抛出异常(我现在不记得哪个命令抛出了异常)。

Currently, each instance of a class has its own OleDbConnection property, so that if I need to, I'm able to close it and release the table it works on.目前,class 的每个实例都有自己的 OleDbConnection 属性,因此如果需要,我可以关闭它并释放它工作的表。 While this works, it's not optimal, and I'd prefer to have 1 connection instance.虽然这可行,但它不是最优的,我希望有 1 个连接实例。

// Elsewhere, ideally one connection for the entire process,
// if I'm able to release locks
public OleDbConnection Connection { get; } = new OleDbConnect();



// ...


if(Connection.State == ConnectionState.Closed) {
    Connection.ConnectionString = "Provider=vfpoledb.dll;Data Source=J:\\epdata\\;Mode=Share Exclusive"
    Connection.Open();
}
OleDbCommand cmd = new OleDbCommand("SET DELETED OFF", Connection);
cmd.ExecuteNonQuery();

cmd.CommandText = "SELECT * FROM tran";
OleDbDataAdapter adap = new OleDbDataAdapter(cmd);
DataTable table = new DataTable();
adap.Fill(table);


// Something here to release the lock on the tran table

This works to the point where it will select the data and lock the table for exclusive use by the current OleDbConnection, but I cannot find any way to release that exclusive lock without closing the entire connection, which I'm trying to avoid having to do.这工作到它将 select 数据并锁定表以供当前 OleDbConnection 独占使用,但我找不到任何方法来释放该独占锁而不关闭整个连接,我试图避免这样做.

I don't see a point opening a connection exclusively and then using an adapter to fill a table, after which you want to release lock.我没有看到专门打开连接然后使用适配器填充表的点,之后您想要释放锁定。 You don't need a connection in the first place, adapter opens and closes the connection as needed:您首先不需要连接,适配器会根据需要打开和关闭连接:

DataTable table = new DataTable();
new OleDbDataAdapter("SELECT * FROM tran", 
      @"Provider=vfpoledb;Data Source=J:\epdata;Deleted=off")
  .Fill(table);

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

相关问题 DBF文件的备注字段仅使用VFP OLE DB Provider for .NET返回一些字符 - Memo field from DBF file only returns a few characters using VFP OLE DB Provider for .NET 使用OLE DB .NET Provider插入数据库表将不起作用 - Insert into database table with OLE DB .NET Provider won't work 如何获得提供者名称以打开Ole DB连接? - How do I get provider name to open Ole DB connection? 未在ConnectionString中指定OLE DB提供程序。 例如,“ Provider = SQLOLEDB;” - An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;' 未在ConnectionString中指定OLE DB提供程序。 '提供者= SQLOLEDB - An OLE DB Provider was not specified in the ConnectionString. 'Provider=SQLOLEDB 未在ConnectionString中指定OLE DB提供程序。 'Provider = SQLOLEDB; - An OLE DB Provider was not specified in the ConnectionString. 'Provider=SQLOLEDB; 如何解决OLE DB访问接口Microsoft ACE OLEDB 12.0对于链接服务器(空)的错误? - How to resolve OLE DB provider Microsoft ACE OLEDB 12.0 for linked server (null) error? Microsoft Office 12.0 Access 数据库引擎 OLE DB 提供程序 - Microsoft Office 12.0 Access database engine OLE DB Provider 以编程方式添加SSIS连接 - OLE DB的Oracle提供程序 - Adding SSIS Connections Programmatically - Oracle Provider for OLE DB IIS和OLE DB外部表的格式不正确 - IIS and OLE DB External table is not in the expected format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM