423,516 Members | 2,068 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,516 IT Pros & Developers. It's quick & easy.

Updating FoxPro DBF From C#

P: n/a
I am trying to Delete records from Fox Pro Free Tables (.DBF) using
C#. I am able to insert and view data with no problems but when I try
to delete - no luck. It appears that I need to run a "Pack" command
but I receive the error "File must be opened exclusively." on the Pack
Command. The code is below and the first command "Delete From
Progress" marks all rows for deletion but does not remove them. I've
tried Exclusive=On but still get the same error.
public FoxProConnector(string tableName){
this.DBFTableName = tableName;
OleDbConnection oConn = new OleDbConnection(@"Provider=VFPOLEDB.1;Data
Source=c:\\" + tableName +";Mode=ReadWrite;");
oConn.Open();
//OleDbCommand oCom = new OleDbCommand("Insert into
Progress(nProgress) values(990)");
OleDbCommand oCom = new OleDbCommand("Delete From Progress");
oCom.Connection = oConn;
oCom.ExecuteNonQuery();
oCom = new OleDbCommand("PACK");
oCom.Connection = oConn;
oCom.ExecuteNonQuery();
}

Unhandled Exception: System.Data.OleDb.OleDbException: File must be
opened exclusively.
**Removed Several Lines**
at OrderHeader.Form1.Main() in c:\documents and settings\scottm\my
documents\visual studio projects\orderheader\form1.cs:line 126
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
aaa,

Technically, when you issue a delete, the rows are flagged with a delete
flag. You aren't going to see those rows on subsequent selects unless the
runtime for foxpro has "SET DELETE ON". If you want to pack the tables, you
shouldn't do this after every database operation, as it can be costly. I
would recommend issuing a pack as part of a regular maintinence and not on
every database operation.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<aaa> wrote in message news:ej*************@TK2MSFTNGP10.phx.gbl...
I am trying to Delete records from Fox Pro Free Tables (.DBF) using
C#. I am able to insert and view data with no problems but when I try
to delete - no luck. It appears that I need to run a "Pack" command
but I receive the error "File must be opened exclusively." on the Pack
Command. The code is below and the first command "Delete From
Progress" marks all rows for deletion but does not remove them. I've
tried Exclusive=On but still get the same error.
public FoxProConnector(string tableName){
this.DBFTableName = tableName;
OleDbConnection oConn = new OleDbConnection(@"Provider=VFPOLEDB.1;Data
Source=c:\\" + tableName +";Mode=ReadWrite;");
oConn.Open();
//OleDbCommand oCom = new OleDbCommand("Insert into
Progress(nProgress) values(990)");
OleDbCommand oCom = new OleDbCommand("Delete From Progress");
oCom.Connection = oConn;
oCom.ExecuteNonQuery();
oCom = new OleDbCommand("PACK");
oCom.Connection = oConn;
oCom.ExecuteNonQuery();
}

Unhandled Exception: System.Data.OleDb.OleDbException: File must be
opened exclusively.
**Removed Several Lines**
at OrderHeader.Form1.Main() in c:\documents and settings\scottm\my
documents\visual studio projects\orderheader\form1.cs:line 126

Nov 15 '05 #2

P: n/a
In news:%2******************@TK2MSFTNGP10.phx.gbl,
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> posted:
Technically, when you issue a delete, the rows are flagged with a
delete flag. You aren't going to see those rows on subsequent
selects unless the runtime for foxpro has "SET DELETE ON".


Hi Nicholas,

The FoxPro command SET DELETED ON hides deleted records. It corresponds to
the Deleted checkbox in the ODBC driver setup - in other words, when the box
is checked, DELETED is ON and deleted records are hidden. A little
counterintuitive.

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
ci**************@mvps.org, www.cindywinegarden.com
Nov 15 '05 #3

P: n/a
In news:ej*************@TK2MSFTNGP10.phx.gbl,
aaa <aaa> posted:
I am trying to Delete records from Fox Pro Free Tables (.DBF) using
C#. I am able to insert and view data with no problems but when I try
to delete - no luck. It appears that I need to run a "Pack" command
but I receive the error "File must be opened exclusively." on the Pack
Command.
When a FoxPro record is marked for deletion you can consider it to be
deleted, as long as you're running with Deleted set ON. The reasons to
permanently remove records are few - if your tables are becoming impossibly
large, or if you need to re-use a primary key. IMHO a key value that's
reused isn't really a PK. Is there some specific reason you need to PACK the
table? Be aware that having exclusive use of the table can only be done when
the users are out of the system.
The code is below and the first command "Delete From
Progress" marks all rows for deletion but does not remove them. I've
tried Exclusive=On but still get the same error.
Um - which error - do you get an error from the Delete command, an error
when you try to PACK, or an error when you try some operation that requires
the records to be permanently removed?
....
oCom = new OleDbCommand("PACK"); Unhandled Exception: System.Data.OleDb.OleDbException: File must be
opened exclusively.


The following article describes how to PACK a table via ODBC. It should help
you get started doing it through OLE DB:

HOWTO: Pack a Table Through the Visual FoxPro ODBC Driver (VFPODBC.dll)
http://support.microsoft.com/default...b;en-us;234756

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
ci**************@mvps.org, www.cindywinegarden.com
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.