如何从需要独占访问 table 的 C# 执行 foxpro 2.6(DOS) 命令?

How to execute foxpro 2.6(DOS) commands from C# that needs exclusive access to table?

这是我的代码,我想删除名为 SMS_DATA 的 FoxPro table 的所有数据,我试过 ZAP 命令,以及还尝试了 DELETE ALLPACK 命令与 USE -table-名称,但它不起作用,并给出以下异常:

System.Data.OleDb.OleDbException (0x80004005): File must be opened exclusively.

这是我的代码:

     string USETBL ="EXECSCRIPT([USE SMS_DATA && Open SMS_DATA table])";
     string DELETE="EXECSCRIPT([DELETE ALL])";       
     string PACK="EXECSCRIPT([PACK])";

                       OleDbConnection con = new OleDbConnection(conStr);
                       try
                       {

                           OleDbCommand cmd  = new OleDbCommand(USETBL, con);
                           OleDbCommand cmd1 = new OleDbCommand(DELETE, con);
                           OleDbCommand cmd2 = new OleDbCommand(PACK, con);

                           con.Open();
                           err.log("connection opened");
                           cmd.ExecuteNonQuery();
                           err.log("table in use");
                           cmd1.ExecuteNonQuery();
                           err.log("delete executed.");
                           cmd2.ExecuteNonQuery();
                           err.log("pack executed.");
                           con.Close();
                       }
                       catch (Exception e)
                       {
                           err.log("Exception:-" + e);
                       }

你的第一行应该是:

EXECSCRIPT([USE SMS_DATA EXCLUSIVE && Open SMS_DATA table]);

为了安全起见,我还将接下来的两行更改为:

string DELETE="EXECSCRIPT([DELETE ALL IN SMS_DATA])";       
string PACK="EXECSCRIPT([PACK IN SMS_DATA])";