Visual Studio 2010 and FoxPro 9.0 runtime Error: "Feature is not available."

hal picture hal · May 31, 2012 · Viewed 7.2k times · Source

Dear Stackoverflow community,

I am a little bit confused using the VFPOleDb Library (9.0Sp2) in Visual Studio 2010 with .NET 4.0 Client Profile. What do I want to do? Edit existing and create new FoxPro Database files using C#.

Trying to compile my own example and based upon the examples seen in "How to create a dbf file from scratch in C#" (1), "How do I read a FoxPro 8.0 database from C#" (2) and "Programming databasing with Visual FoxPro" (3) I receive a compilation error: "Feature not available". Stacktracing the Exception Message shows me that the OleDbConnection Factory doesn't recognize the connection string? I already added the 'Interop.VFPOLEDBLib' as a Reference but I wasn't able to add the 'vfpoledb.dll' because of a missing manifest file?

Code-Example

using System;
using System.IO;
using System.Data;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Data.Common;


    namespace VFPExample
    {

        class VFPExample
        {
            /*
            https://stackoverflow.com/questions/754436/odbc-dbf-files-in-c-sharp/

            http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic62548.aspx
            */

            static void Main(String[] args)
            {

                {
                    string strTestDirectory = @"Provider=VFPOLEDB.1; DataSource=D:\TEMP\";

                    using (OleDbConnection vfpro_con_insert =
                    new OleDbConnection(strTestDirectory) )
                    {
                    vfpro_con_insert.Open(); // FIXME: Ex.Message: "Feature not available"; 

                    OleDbCommand createTable = new OleDbCommand(@"Create Table TestDBF (Field1 I, Field2 C(10))", vfpro_con_insert);
                    OleDbCommand insertTable1 = new OleDbCommand(@"Insert Into TestDBF Values (1, 'Hello')", vfpro_con_insert);
                    OleDbCommand insertTable2 = new OleDbCommand(@"Insert Into TestDBF Values (2, 'World')", vfpro_con_insert);

                    createTable.ExecuteNonQuery();
                    insertTable1.ExecuteNonQuery();
                    insertTable2.ExecuteNonQuery();

                    Console.WriteLine("Wrote in " + vfpro_con_insert.DataSource);
                    }

                    Console.ReadLine();

                    /*
                --------------------------------------------------------------------------------
                    */

                    using (OleDbConnection vfpro_con_read = new OleDbConnection(strTestDirectory))
                    {
                        vfpro_con_read.Open();

                        OleDbCommand readTable = new OleDbCommand("Select * From TestDBF (Field1 I, Field2 C(10))", vfpro_con_read);

                        OleDbDataAdapter da = new OleDbDataAdapter(readTable);

                        DataSet ds = new DataSet();
                        //  DataRow dr = new DataRow();

                        da.Fill(ds);

                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            Console.WriteLine(dr.ItemArray[1].ToString());
                        }

                    }

                    Console.ReadLine();

                }
                catch (Exception e)
                {
                    Console.WriteLine("\n\n Exception:\n\n{0}", e.Message); // Set Breakpoint here for detailed StackTrace
                }
            }

        }
    }

StackTrace

> e {"Feature is not available."}   System.Exception {System.Data.OleDb.OleDbException}
>       [System.Data.OleDb.OleDbException]
>       {"Feature is not available."}
>       System.Data.OleDb.OleDbException
> Data  {System.Collections.ListDictionaryInternal}
>        System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
> HelpLink  null    string
> InnerException    null    System.Exception
> Message   "Feature is not available." string
> Source    "Microsoft OLE DB Provider for Visual FoxPro"   string
> StackTrace    "
>    at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
>    at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
>    at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
>    at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
>    at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
>    at System.Data.OleDb.OleDbConnection.Open()
>    at bestsellerList.VFPExample.Main(String[] args)
>    in  D:\Visual Studio 2010\Projects\VFPExample\VFPExample.cs:Line 37."  string
> TargetSite    {Void .ctor(System.Data.OleDb.OleDbConnectionString, System.Data.OleDb.OleDbConnection)}    System.Reflection.MethodBase {System.Reflection.RuntimeConstructorInfo}
>    Static Member      
>    No(t) public Member        
> e.Message "Feature is not available." string

(Tried to fix localization)

So I need some clarifications regarding VFPOleDb/ Visual FoxPro in Visual Studio:

  • Is the Visual FoxPro Library only supported with .NET Client Profile 2.0 and/or Visual Studio 2003/5 (and earlier)? Besides I can clearly see that VSFoxPro (5) reached its End of Product Lifecycle (4) -- at least for Mainstream Support. Extended Support is still granted until 2015. Are there any other (semi)official Documents or Blog entries from Microsoft regarding migration of FoxPro Databases? Already seen "Migrating from Visual FoxPro" (6).

  • Are there any successful compilations reported with .NET 3.x (Client Profile) and above?

  • What am I missing in my code example and/or Reference in Visual Studio?


So, I took the example-code, modified it to my needs -- to read one table with six columns and many, many rows which is exported as a csv file; works fine on my local machine (as usual, as we all know) -- and copied the executable to a Windows 2008 Server R2 with installed .NET 3.5.x and tried to start the application. Did you already do a well educated guess?

Once again I receive the same Exception as the first time but this time it looks like that

            DataSet ds = new DataSet();
            da.Fill(ds); // throws Exception

da.Fill(ds) is the troublemaker but this makes really no sense for me, because I also copied the compiled example-application based on the corrected code to the server and it just does what it is supposed to do...

Thanks for any hints.

Exception

System.Data.OleDb.OleDbException: Feature is not available.
   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   at Program.Main(String[] args)


System.Collections.ListDictionaryInternal

   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   at Program.Main(String[] args)

Answer

hal picture hal · Jun 1, 2012

I fixed the code as proposed, cleaned it up and improved some minor parts. It works.

using System;
using System.IO;
using System.Data;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Data.Common;

namespace VFPExample
{
    class VFPExample
    {
        /*
         * http://stackoverflow.com/questions/754436/odbc-dbf-files-in-c-sharp/
         * http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic62548.aspx
         */
        static void Main(String[] args)
        {
            try
            {
                string strTestDirectory = @"Provider=VFPOLEDB.1; Data Source=D:\TEMP\";

                using (OleDbConnection vfpro_con_insert = new OleDbConnection(strTestDirectory) )
                {
                    vfpro_con_insert.Open(); 

                    OleDbCommand createTable = new OleDbCommand(@"Create Table TestDBF (Field1 N(2,0), Field2 C(10))", vfpro_con_insert);
                    OleDbCommand insertTable1 = new OleDbCommand(@"Insert Into TestDBF (Field1, Field2) Values (1, 'Hello')", vfpro_con_insert);
                    OleDbCommand insertTable2 = new OleDbCommand(@"Insert Into TestDBF (Field1, Field2) Values (2, 'World')", vfpro_con_insert);

                    createTable.ExecuteNonQuery();
                    insertTable1.ExecuteNonQuery();
                    insertTable2.ExecuteNonQuery();

                    Console.WriteLine("Wrote in " + vfpro_con_insert.DataSource);
                }

                Console.ReadLine();

                using (OleDbConnection vfpro_con_read = new OleDbConnection(strTestDirectory))
                {
                    Console.WriteLine("Read from " + vfpro_con_read.DataSource);

                    vfpro_con_read.Open();

                    OleDbCommand readTable = new OleDbCommand(@"Select * From TestDBF", vfpro_con_read);

                    OleDbDataAdapter da = new OleDbDataAdapter(readTable);

                    DataSet ds = new DataSet();

                    da.Fill(ds);

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        Console.WriteLine(dr.ItemArray[1].ToString());
                    }
                }
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("\n\n Exception:\n\n{0}", e.Message); // Set Breakpoint here for detailed StackTrace
            }
        }
    }
}