Reputation: 10648
I have an ASP.NET MVC application which is compiled as "Any CPU".
I have correctly installed Microsoft OLE DB Provider for Visual FoxPro 9.0 from here.
Now I am trying to open a dbf file (that exists) using below snippet code:
string conString = @"Provider=VFPOLEDB.4;Data Source=" + dbfFilePath + ";Extended Properties=dBASE IV;";
using (dBaseConnection = new OleDbConnection(conString))
{
dBaseConnection.Open();
// Some stuff
}
Above code is working correctly when I set to true the feature "Enable 32-bit Applications" from application pool advanced settings:
IIS Manager -> Application Pools -> My Application Pool -> Advanced Settings, I have set to true the setting "Enable 32-bit Applications"
Doing so, I force the process to execute in 32-bit mode and since microsoft visual foxpro OLED DB provider is in x86 then it works perfectly without problems.
Now I need to execute my ASP.NET MVC application in 64-bit mode only so I have set to false the feature "Enable 32-bit Applications". After that the above snippet code stops working. When trying to execute below line of code:
dBaseConnection.Open();
...it throws below exception:
VFPOLEDB.4 provider is not registered on the local machine
...and its stack trace:
at System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper)
at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at d:\MyProjects\MyASPNetMvcApp\VfpHelper.cs:line 115
How can I make this to run as a 64-bit process (i mean with feature "Enable 32-bit Applications" disabled - set to false)?
Upvotes: 0
Views: 2265
Reputation: 23797
Actually I wasn't using that driver (32 bits ODBC version) since years, I downloaded and tested the 64 bits one (OLEDB).
This code shows an error messagebox which I don't have an idea about ("Exception code C0000005 was generated when calling the user-supplied callbackfunction. It is being disabled."), BUT after you click OK it works (tried with Select and Update): Probably that error message might have something in driver docs.
void Main()
{
string dbfFilePath = @"C:\PROGRAM FILES (X86)\MICROSOFT VISUAL FOXPRO 9\SAMPLES\Data";
string conString = @"Provider=Advantage OLE DB Provider;Data Source=" + dbfFilePath + ";ServerType=ADS_LOCAL_SERVER;TableType=ADS_VFP;";
DataTable t = new DataTable();
using (OleDbConnection cn = new OleDbConnection(conString))
using (OleDbCommand cmd = new OleDbCommand("select * from Customer", cn))
{
cn.Open();
t.Load(cmd.ExecuteReader());
cn.Close();
}
t.Dump(); // tested in LinqPad AnyCPU version
}
EDIT: With fullpath to dbf:
void Main()
{
string dbfFullFilePath = @"C:\PROGRAM FILES (X86)\MICROSOFT VISUAL FOXPRO 9\SAMPLES\Data\Customer.dbf";
string conString = @"Provider=Advantage OLE DB Provider;Data Source=" + Path.GetDirectoryName(dbfFullFilePath) + ";ServerType=ADS_LOCAL_SERVER;TableType=ADS_VFP;";
DataTable t = new DataTable();
using (OleDbConnection cn = new OleDbConnection(conString))
using (OleDbCommand cmd = new OleDbCommand($"select * from {Path.GetFileNameWithoutExtension(dbfFullFilePath)}", cn))
{
cn.Open();
t.Load(cmd.ExecuteReader());
cn.Close();
}
t.Dump(); // tested in LinqPad AnyCPU version
}
PS: This works without any error message on first run. On repeated run it displays the exception I mentioned before. Should be related to object disposal.
EDIT2: I forgot to mention, the foldername in connection string is not really important and you could select with fullpath. ie:
void Main()
{
string dbfFullFilePath = @"C:\PROGRAM FILES (X86)\MICROSOFT VISUAL FOXPRO 9\SAMPLES\Data\Customer.dbf";
string conString = @"Provider=Advantage OLE DB Provider;Data Source=c:\temp;ServerType=ADS_LOCAL_SERVER;TableType=ADS_VFP;";
DataTable t = new DataTable();
using (OleDbConnection cn = new OleDbConnection(conString))
using (OleDbCommand cmd = new OleDbCommand($"select * from [{dbfFullFilePath}]", cn))
{
cn.Open();
t.Load(cmd.ExecuteReader());
cn.Close();
}
t.Dump(); // tested in LinqPad AnyCPU version
}
Upvotes: 1