Error "Unable to find the requested .Net Framework Data Provider. It may not be installed"
I am using Visual Studio 2008 and oracle database 10g.
I trying to connect to the backend like this:
Subwindow "Server explorer". Push button "Connect to database" and make next chain Data Connection->Choose Data Source->Oracle Database->oracle Data provider for .Net->Continue->Data Source name : oraclexe->Userneme: hr password: hr -> Test connection (answer "Test connected succeeded ")->push button OK and:
"Unable to find the reque开发者_运维百科sted .Net Framework Data Provider. It May not be installed"
I have made changes to machine.config
<add name="Oracle Data Provider for .NET"
invariant="Oracle.DataAccess.Client" description="Oracle Data Provider for .NET"
type="Oracle.DataAccess.Client.OracleClientFactory,
Oracle.DataAccess, Version=2.111.6.20, Culture=neutral, PublicKeyToken=89b483f429c47342" />
But then to same error persists. What to do?
Oracle data providers are specific for an architecture. If you download a 64-bit driver you need to build your application as 64bit (or AnyCPU if the target OS is 64bit).
The problem is that Visual Studio is 32-bit, so you also need a 32bit driver installed.
A couple of suggestions:
- Don't use the EF beta. If you do, use the 32-bit version. The driver does not work as advertised as of October 2010, the install was misconfigured for 64 bit applications and odac dll's were placed in the wrong system folder, aside from other issues.
- Stick with ado.net and do some simple queries before tackling the project, if you are using someone else's project or downloaded it from somewhere.
- Visual studio project files keep suggested locations for assemblies in the project file, look for those and remove the "hint" path if this is someone else's project.
- Download and install the client files: http://www.oracle.com/technology/software/tech/windows/odpnet/index.html since you did not specify that you have the client files installed.
In summary, you are probably using one version of the driver for the design tool and another for the underlying connections. I know this sounds weird but I've run into it several times already. The only way forward is to take it apart. If you start with an ADO.NET base connection test you'll find the problem.
Below is a simple connection to get started.
Thanks,
Aldo
using System;
using System.Data.Common;
using Oracle.DataAccess.Client;
namespace EntityFrameworkForOracle
{
internal class Test1Connection
{
internal void InternalTestRead()
{
using (var con = Database.GetLocalConnection())
{
con.Open();
var cmd = Database.GetCommand(con);
const string sql = @"select *
from TESTTABLE";
cmd.CommandText = sql;
var reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine("\t{0}\t{1}", reader[0], reader[1]);
}
reader.Close();
con.Close();
con.Dispose();
cmd.Dispose();
}
}
}
public static class Database
{
private const string ProviderName = "Oracle.DataAccess.Client";
private const string LocalConnectionString = "User Id=system;Password=XXX;Data Source=localhost:XXXX/XXXX;enlist=true;pooling=true";
private static readonly DbProviderFactory Factory = DbProviderFactories.GetFactory(ProviderName);
public static DbCommand GetCommand(DbConnection con)
{
var cmd = Factory.CreateCommand();
if (cmd != null)
{
cmd.Connection = con;
return cmd;
}
return null;
}
public static DbCommand GetCommand(string cmdText, DbConnection con)
{
var cmd = GetCommand(con);
cmd.CommandText = cmdText;
return cmd;
}
public static DbConnection GetLocalConnection()
{
var con = Factory.CreateConnection();
if (con != null)
{
con.ConnectionString = LocalConnectionString;
return con;
}
return null;
}
public static void CloseConnection(OracleConnection connection)
{
connection.Close();
connection.Dispose();
}
}
}
精彩评论