Michel I would say that since you always using the same connection the table is already open, my guess is to do something like
IF !USED(table name)
USE table name in 0
ENDIF
Also why don't you have only one execscript with all the statements?
you could use a string builder to build the VFP commands adding vbCRLF to the end of each line and then do something like
loDataProviderBackup.CommandTextAdd("EXECSCRIPT([" & stringbuilder.tostring & "])")
This should be more efficient.
>I am unable to execute the VFP ExecScript() COPY TO command on a VFP table if a data adapter connection is opened using the table. In the following code, I am issuing SET SAFETY OFF and SET EXCLUSIVE OFF before doing the COPY TO:
>
>
> loDataProviderBackup.CommandTextAdd("EXECSCRIPT(""SET SAFETY OFF"")")
> loDataProviderBackup.CommandTextAdd("EXECSCRIPT(""SET EXCLUSIVE OFF"")")
> loDataProviderBackup.CommandTextAdd("EXECSCRIPT(""USE " + lcTable + """)")
> loDataProviderBackup.CommandTextAdd("EXECSCRIPT(""COPY TO '" + lcDirectory + lcTable + "'"")")
> loDataProviderBackup.CommandTextAdd("EXECSCRIPT(""USE"")")
>
> ' Index
> If Not loDataProviderBackup.ExecuteNonQuery() Then
> Return False
> End If
>
>
>But, if I have another data provider object having a connection opened on a table that I need to copy, I have a "File is in use" error.
>
>Anyone has a better approach to backup a VFP table from .NET where I would avoid the "File is in use" error message?
Alexandre Palma
Senior Application Architect