C# Visual Studio 2010和FoxPro 9.0运行时错误:“0”;功能不可用。”;
亲爱的社区: 在VisualStudio2010中使用VFPOleDb库(9.0Sp2)和.NET4.0客户端配置文件时,我有点困惑。 我想做什么?使用C#编辑现有的FoxPro数据库文件并创建新的FoxPro数据库文件 尝试编译我自己的示例,根据“如何在C#中从头开始创建dbf文件”()、“如何从C#中读取FoxPro 8.0数据库”()和“使用Visual FoxPro编程数据库”()中看到的示例,我收到一个编译错误:“功能不可用”。 Stacktracing异常消息显示OleDbConnection工厂无法识别连接字符串? 我已经添加了“Interop.VFPOLEDBLib”作为引用,但由于缺少清单文件,我无法添加“vfpoledb.dll” 代码示例C# Visual Studio 2010和FoxPro 9.0运行时错误:“0”;功能不可用。”;,c#,visual-studio,oledb,foxpro,dbf,C#,Visual Studio,Oledb,Foxpro,Dbf,亲爱的社区: 在VisualStudio2010中使用VFPOleDb库(9.0Sp2)和.NET4.0客户端配置文件时,我有点困惑。 我想做什么?使用C#编辑现有的FoxPro数据库文件并创建新的FoxPro数据库文件 尝试编译我自己的示例,根据“如何在C#中从头开始创建dbf文件”()、“如何从C#中读取FoxPro 8.0数据库”()和“使用Visual FoxPro编程数据库”()中看到的示例,我收到一个编译错误:“功能不可用”。 Stacktracing异常消息显示OleDbConne
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
StackTrace
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客户端配置文件2.0和/或Visual Studio 2003/5(及更早版本)? 此外,我可以清楚地看到VSFoxPro()已经到达了产品生命周期的终点()——至少在主流支持方面是如此。到2015年,仍将提供长期支持。 微软是否有其他(半)官方文件或博客关于FoxPro数据库迁移的内容?已经看过“从Visual FoxPro迁移”()
- 是否有使用.NET3.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)
我使用VFPOleDb使用VS2010构建WPF应用程序,没有问题。。。不过我是在32位开发机器上运行的。VFP不支持64位句点,不知道您是否遇到了这种情况 还有。。。路径“D:\TEMP”是否存在?它不会自动尝试创建路径,但在我看来,这会抛出一个不同的错误 您还可以删除System.Data.ODBC和System.Data.Common,我认为您正在使用的示例中不需要这些 我也没有任何“Interop.VFPOLEDBLib”的显式add引用。从我所遇到的情况来看,只有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();
}
看看这会不会崩溃。。。如果是这样的话,您知道这与创建、插入、选择的任何其他准备工作无关,而是显式地连接。异常“功能不可用”是由于连接字符串不正确造成的。使用“数据源”而不是“数据源”。我按照建议修复了代码,清理了它并改进了一些小部分。它起作用了
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
}
}
}
}
抱歉-我不清楚您所说的“VFP不支持64位--PERIOD”是什么意思。IDE和使用它生成的应用程序运行良好,并且在64位Windows上受支持。或者你的意思是什么?@AlanB,64位可能支持向后调用/运行32位,但VFP无法利用64位。。ie:max numeric value,32位,每个表的记录数仍然限制为每个文件2-gig,等等。是的,这是正确的,但目前在64位Windows上运行的所有没有本机64位可执行文件的文件中,有很大一部分也是正确的。2GB限制早在64位之前就存在了,它是所使用的传统文件锁定机制的一个功能。32位数字,是的,这在任何开发产品中多久出现一次问题?一句话:它和64位Windows上的任何其他32位应用程序一样受支持(直到2014年)。@DRapp好吧,它是64位系统,但在这种情况下,只要将项目首选项设置为32位兼容模式并且正确安装了驱动程序,示例就可以编译。你说得对。我错过了代码>数据源< /代码>中的空白,这引起了异常。哇!完美的正是我所需要的,我一直在到处寻找。我有连接字符串,我有查询,我只是不知道如何从这些FoxPro数据库中提取数据。谢谢你+1.