Visual Studio 2010和FoxPro 9.0运行时错误:“功能不可用。”

时间:2012-05-31 16:15:09

标签: c# visual-studio oledb foxpro dbf

亲爱的Stackoverflow社区,

在使用.NET 4.0 Client Profile的Visual Studio 2010中使用VFPOleDb库(9.0Sp2)时,我有点困惑。 我想做什么?使用C#编辑现有的并创建新的FoxPro数据库文件。

尝试编译我自己的示例,并基于“如何在C#中从头开始创建dbf文件”(1)中的示例,“如何从C#读取FoxPro 8.0数据库”({ {3}})和“用Visual FoxPro编程数据库”(2)我收到一个编译错误:“功能不可用”。 Stacktracing异常消息向我显示OleDbConnection Factory无法识别连接字符串? 我已经添加了'Interop.VFPOLEDBLib'作为参考,但由于缺少清单文件,我无法添加'vfpoledb.dll'?

代码示例

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
                }
            }

        }
    }

栈跟踪

> 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

(试图修复本地化)

所以我需要在Visual Studio中对VFPOleDb / Visual FoxPro进行一些澄清:

  • Visual FoxPro库是否仅支持.NET Client Profile 2.0和/或Visual Studio 2003/5(及更早版本)? 此外,我可以清楚地看到VSFoxPro(3)已达到其产品生命周期结束(5) - 至少对于主流支持而言。延期支持仍然授予2015年。 Microsoft是否有关于FoxPro数据库迁移的其他(半)官方文档或博客条目?已经看过“从Visual FoxPro迁移”(4)。

  • 是否有使用.NET 3.x(客户端配置文件)及以上版本报告的成功编辑?

  • 我在代码示例和/或Visual Studio中的参考中缺少什么?


所以,我把示例代码修改为我的需要 - 读取一个包含六列和多行的表,这些行作为csv文件导出;在我的本地计算机上正常工作(像往常一样,我们都知道) - 并将可执行文件复制到安装了.NET 3.5.x的Windows 2008 Server R2并尝试启动该应用程序。你有没有受过良好教育的猜测?

我再次收到与第一次相同的例外情况,但这次看起来像是

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

da.Fill(ds)是麻烦制造者,但这对我来说真的没有意义,因为我还将基于纠正后的代码的已编译的示例应用程序复制到服务器上,它只是做它应该做的事情......

感谢任何提示。

异常

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)

3 个答案:

答案 0 :(得分:3)

我修改了建议的代码,清理了它并改进了一些小部件。它有效。

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
            }
        }
    }
}

答案 1 :(得分:2)

“功能不可用”异常是由于连接字符串不正确引起的。使用“数据源”而不是“数据源”。

答案 2 :(得分:0)

我使用VFPOleDb使用VS2010构建WPF应用程序没有问题...我正在运行32位开发机器。 VFP不支持64位 - PERIOD,并且不知道这可能是你遇到的问题。

另外......路径“D:\ TEMP”是否存在?它不会自动尝试创建路径,但在我看来会抛出不同的错误。

您也可以删除System.Data.ODBC和System.Data.Common,我认为您正在使用的示例中不需要这些。

我也没有'Interop.VFPOLEDBLib'的任何显式添加引用。从我遇到的,只是拥有System.Data和你拥有的

using System.Data;
using System.Data.OleDb;

应该很好。 OleDB提供程序在尝试加载“Provider = VFPOLEDB.1;”时会实际查看“已注册”的内容。部分。

那就是说,我会先把它变得更简单......只是尝试打开连接然后关闭它

static void Main(String[] args)
{
   string strTestDirectory = @"Provider=VFPOLEDB.1; DataSource=D:\TEMP\";

   OleDbConnection VFPConn = new OleDbConnection(strTestDirectory);
   VFPConn.Open();
   if( VFPConn.State == System.Data.ConnectionState.Open )
      VFPConn.Close();
}

看看这是否崩溃......如果是这样,你知道它与创建,插入,选择的任何其他准备工作没有任何关系,但显然是连接。