親愛的Stackoverflow社區,Visual Studio 2010和FoxPro 9.0運行時錯誤:「功能不可用」。
我有點困惑使用Visual Studio 2010中的VFPOleDb庫(9.0Sp2)與.NET 4.0客戶端配置文件。 我想做什麼?編輯現有的並使用C#創建新的FoxPro數據庫文件。
試圖編譯我自己的示例,並基於「如何在C#中從頭開始創建dbf文件」(1),「如何從C#讀取FoxPro 8.0數據庫」(2)和「使用Visual FoxPro編程數據庫「(3)我收到編譯錯誤:」功能不可用「。 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中一些澄清:
是否僅支持.NET Client Profile 2.0和/或Visual Studio 2003/5(及更早版本)的Visual FoxPro庫? 除了我可以清楚地看到VSFoxPro(5)達到了其產品生命週期結束(4) - 至少對於主流支持。擴展支持仍然授予到2015年。 是否有Microsoft的其他(半)官方文檔或博客條目遷移FoxPro數據庫?已經看到「從Visual FoxPro遷移」(6)。
是否有任何與.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)
你說得對。我錯過了'Data Source'中的空白,這導致了異常。 – hal