Error 0152: No Entity Framework provider found for 'Oracle.DataAccess.Client' ADO.NET provider - oracle

I have Windows 7 x64, Visual Studio 2012 with the 'ODAC 11.2 Release 5 and Oracle Developer Tools for Visual Studio (11.2.0.3.20)'.
Then I connected to Oracle db, create .edmx model. But when I'm trying to use EF to operate some data
var ent = new Entities();
var res = ent.table1.ToList();
Error happends
Schema specified is not valid. Errors:
Model.ssdl(2,2) : error 0152: No Entity Framework provider found for
'Oracle.DataAccess.Client' ADO.NET provider. Make sure the provider is registered in
the 'entityFramework' section of the application config file. See
http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
I checked my AppConfig, all sections are ok. Also I installed ODAC1120320Xcopy_x64 (and added a environment variables too). But nothing changes.
If I do it in this way, all works fine
EntityConnection econn = new EntityConnection("name=Entities");
econn.Open();
EntityCommand ecmd = econn.CreateCommand();
ecmd.CommandText = "SELECT e.NAME FROM Entities.table1 as e";
EntityDataReader ereader = ecmd.ExecuteReader(CommandBehavior.SequentialAccess);
while (ereader.Read()) { ... }
Have you any ideas? Will be very grateful for any help.

Related

Azure Functions, Entity Framework and Oracle DB - basic POC fails

I'm having a lot of trouble getting a basic proof-of-concept working, in which I am accessing an Oracle DB (11g) through Azure Functions via Entity Framework (6.2).
Prerequisites:
ODT For Visual Studio 2017 is installed, as well as Azure Functions CLI/Core Tools. Everything mentioned below is done entirely via Visual Studio 2017, not through Azure portal.
Take 1:
Created a new project with the Azure Functions template.
Installed NuGet packages EntityFramework (6.2.0), Oracle.ManagedDataAccess (12.2.1100) and Oracle.ManagedDataAccess.EntityFramework (12.2.1100). Note: When installing NuGet packages in projects using the Azure Functions template, the packages are added under Dependencies -> NuGet, rather than under References.
Added ADO.NET Entity Data Model to project.
Problem: After setting my connection string, choosing Entity Framework 6.x is unavailable, with the following error message:
An Entity Framework database provider compatible with the latest
version of Entity Framework could not be found for your data
connection. If you have already installed a compatible provider,
ensure you have rebuilt your project before performing this action.
Otherwise, exit this wizard, install a comaptible provider, and
rebuild your project befre performing this action.
As the simplest of workarounds, I have tried to just go ahead with EF5, but it throws an exception while creating the DB model (after selecting the objects to include in model, including some stored procedures).
Take 2:
Created project and installed NuGet packages as above.
Created class library project to facilitate the Oracle interactions.
Installed the same NuGet packages as above in the class library project.
Added ADO.NET Entity Data Model to class library project and added some database objects to the database model. Also added custom constructor to the model for specific connection string, because managing connection strings in Azure Functions was a seperate set of headaches that I'll deal with later.
Added a simple wrapper method to the class library project that calls a stored procedure from the database model:
public static string NameByEmpNo(int empNo)
{
string result;
MyEntities entities = new MyEntities("metadata=res://*/MyEntities.csdl|res://*/MyEntities.ssdl|res://*/MyEntities.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string='DATA SOURCE=127.0.0.1:1521/ORCL;PASSWORD=tiger;USER ID=SCOTT'");
ObjectParameter name = new ObjectParameter("o_empname", typeof(string));
entities.GET_EMP_NAME_PROC(empNo, name);
result = (string)name.Value;
return result;
}
Added reference to the class library in the Azure Functions project.
Added function that calls NameByEmpNo:
[FunctionName("GetNameByEmpNo")]
public static async Task<HttpResponseMessage> GetNameByEmpNo([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequestMessage req, TraceWriter log)
{
int empNo = Int32.Parse(req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "empno", true) == 0)
.Value);
string empName = ScottAccess.NameByEmpNo(empNo);
return req.CreateResponse(HttpStatusCode.OK, "Employee name: " + empName);
}
Problem: At runtime, calling the function fails with this error
message:
Exception while executing function: GetNameByEmpNo -> The ADO.NET
provider with invariant name 'Oracle.ManagedDataAccess.Client' is
either not registered in the machine or application config file, or
could not be loaded. See the inner exception for details. -> Unable to
find the requested .Net Framework Data Provider. It may not be
installed.
Bonus info: My class library works perfectly when called through a console application. Also, my Azure Functions app works perfectly when calling functions that do not use my class library...
I am stumped. Has anyone got experience with getting this combination of techs working together and can offer some insight into where I'm going wrong / provide steps to get a basic connection working?
Entity Framework within Azure Functions defaults the providers to System.Data.SqlClient so SQL connections will work without any configuration changes, but that means you have to do something special for Oracle connections. The problem seems to come from the config values that the Oracle.ManagedDataAccess.Client library assumes are available within the App.Config or Web.Config file in the project, which are inserted whenever you install the Oracle.ManagedDataAcess.EntityFramework Nuget package. Azure Functions don't have config files, and I wasn't able to find any way to specify the Oracle provider in the settings json files.
I found a solution in this post
It suggests bypassing this mechanism and creating a DbConfiguration for Oracle, then using DbConfigurationType to tell the DbContext which configuration you're using.
public class OracleDbConfiguration : DbConfiguration
{
public OracleDbConfiguration()
{
SetDefaultConnectionFactory(new OracleConnectionFactory());
SetProviderServices("Oracle.ManagedDataAccess.Client", EFOracleProviderServices.Instance);
SetProviderFactory("Oracle.ManagedDataAccess.Client", new OracleClientFactory());
}
}
[DbConfigurationType(typeof(OracleDbConfiguration))]
public partial class MyEntities : IGISContext
{
//Expose Connection String Constructor
public MyEntities(string connectionString, int commandTimeoutInSeconds = 30) : base(connectionString)
{
this.Database.CommandTimeout = commandTimeoutInSeconds;
}
}
Note: I used EF 6 Database First to generate my EDMX; MyEntities here is a partial class for providing a constructor that takes in a connection string.
The oracle connection wil use the specified DbConfiguration class, and any SQL database connections will continue to work using the defaults.
My solution is using the Nuget Packages:
EntityFramework 6.2.0
Oracle.ManagedDataAccess 12.2.1100
Oracle.ManagedDataAccess.EntityFramework 12.2.1100

How to clone a record (server side) in Dynamics crm 2016?

I am using crm 2016 and I need to clone a record using plugin, after googling I found out that I need to use Microsoft.Xrm.Client that hold the clone() function - which is not in 2016 SDK because of MS reorganization.This lib is in 2015 SDK.
My questions are :
1. If I'll take that lib from CRM 2015 and use it in 2016 will it be supported?
2. If it's not supported what are my options to clone a record in server side?
The method Clone() in the Microsoft.Xrm.Client only creates a copy of the Entity object in memory. It does not create a copy in the database of CRM. When you need to create a copy in the database just instantiate a new Entity object and pass it to the Create() method of the IOrganizationService interface.
When you really need a deep clone as described on MSDN you could consider writing one yourself. In most scenarios you will only need to copy the objects in the attributes collection. Of those objects only the reference types EntityReference, OptionSetValue and Money wiil need your special attention.
I would not advise to use deprecated libraries.
We use the following helper method to clone an entity - this is an updated version from the original which correctly clones the reference types, and excludes the system attributes
public static Entity CloneEntitySandbox(Entity entityToClone)
{
var newEntity = new Entity(entityToClone.LogicalName);
var systemAttributes = new List<string>();
systemAttributes.Add("createdon");
systemAttributes.Add("createdby");
systemAttributes.Add("modifiedon");
systemAttributes.Add("modifiedby");
systemAttributes.Add("owninguser");
systemAttributes.Add("owningbusinessunit");
foreach (var attribute in entityToClone.Attributes
.Where(x => x.Key != entityToClone.LogicalName + "id")
.Where(x => !systemAttributes.Contains(x.Key)))
{
switch (attribute.Value.GetType().Name)
{
case "Money":
var m = attribute.Value as Money;
newEntity[attribute.Key] = new Money(m.Value);
break;
case "EntityReference":
var er = attribute.Value as EntityReference;
newEntity[attribute.Key] = new EntityReference(er.LogicalName, er.Id);
break;
case "OptionSetValue":
var os = attribute.Value as OptionSetValue;
newEntity[attribute.Key] = new OptionSetValue(os.Value);
break;
default:
newEntity[attribute.Key] = attribute.Value;
break;
}
}
return newEntity;
}
Note that this does not perform the save to create the cloned entity in the CRM database, that's up to you.
Microsoft announcement says:
We also removed Microsoft.Xrm.Client from the CRM 2016 (8.x) SDK client because it was not compliant with the OAuth changes, and replaced it with Microsoft.Xrm.Tooling.Connector. You can use the current Microsoft Dynamics 365 Software Development Kit (SDK) to access Microsoft Dynamics CRM back to version 6.x for both auth and messaging.
Dynamics 365 SDK Backwards Compatibility
You can still use Microsoft.Xrm.Client.dll in your project from older SDK, this maybe supported for a while.
But I would recommend to go with custom Action, taking parent record as EntityReference Input parameter, Retrieve the parent record data + needed related entities & manually create (clone) child record + related entities records in Action.
You can Execute/invoke this Action from client/server side, wherever you want.

How to deploy Entity Framework with Oracle ODAC 12 on WS2012 just copying DLLs

I´ve searched the following links:
How to deploy Oracle with EF
Problems deploying Oracle with EF
And many other posts around regarding Oracle deployment.
Basically I have an C# simple test application to insert some rows into a database (this is a test application. The full application uses a lot of EF stuff):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;
using MzDbLib.DataAccessObject;
using MzDbLib.DatabaseContext;
using MzDbLib.DatabaseModel;
namespace TestDbConnection
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("This program will generate 10 logs into SYSTEMDATALOG table");
///
/// Do a loop of 10 logs generated
///
for (int i = 0; i < 10; i++)
{
string msg = "TEST GENERATED LOG NUMBER " + i.ToString();
Console.Write("Generating log " + i.ToString() + "...");
//
// Connect to database and to the log table
//
Entities dbContext = new Entities();
SYSTEMDATALOG logTable = new SYSTEMDATALOG();
logTable.DATETIME = DateTime.Now;
logTable.TYPE = "INFO";
logTable.SEVERITY = 0;
logTable.SOURCE = "TESTDBCONNECTION";
logTable.USER = "SYSTEM";
logTable.MESSAGE = msg;
dbContext.SYSTEMDATALOG.Add(logTable);
dbContext.SaveChanges();
Console.WriteLine("Done.");
}
Console.WriteLine ("Data generated at the database. Press a key to end test.");
Console.ReadKey();
//
// Application exit
//
Environment.Exit(0);
}
}
}
The dbContext and SYSTEMDATALOG classes were generated though EF model-first from an Oracle database. I´m using Visual Studio 2012 and ODAC 12.1.0.1.0 with Oracle Developer Tools 32-bit installed on development machine. All fresh install and working pretty fine when developing.
All runs fine in DEVELOPMENT, but neve in production.
I´m using in production WINDOWS SERVER 2012. I have tried the following approaches:
a) Install WS2012 from schatch and install ODAC 32-bit version 12.1.0.1.0 fresh from Oracle site. I did run install
with ODAC 4 version.
I got "The provider is not compatible with the version of Oracle client". After some tries and some hours lost, with different approaches, I decided to go to a new method - non-installating Oracle
b) I fresh installed WS2012 and did no ORacle installation. Copied the DLLs stated in the above links and now I´m getting "Unable to find the requested .NET data provider". I´ve copied all the available Oracle DLLs from DEV machine to the WS2012 EXE directory of my application and still getting that error.
My connection string (auto-generated by VS2012) is:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="Entities" connectionString="metadata=res://*/DatabaseModel.DatabaseModel.csdl|res://*/DatabaseModel.DatabaseModel.ssdl|res://*/DatabaseModel.DatabaseModel.msl;provider=Oracle.DataAccess.Client;provider connection string="data source=//ORACLESERVER1:1521/MEZAMES;password=xxx;persist security info=True;user id=MZMESDB"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
This string is being generated into 2 files: TestDbConnection.exe.config and TestDbConnection.vshost.exe.config (I´m copying the bin/Debug folder to the server).
So, I need help to deploy my app to the new server. Some questions:
a) Which DLL is needed to go with the application for ODAC 12.1.0.1 ? Does that changed from ODAC 11 ?
b) Is that last error regarding EF or Oracle ?
c) Why does VS generated 2 config files ?
d) Does "providerName="System.Data.EntityClient" is the cause of the error ? If so, what DLL should be copied together.
e) Is there any tool/way to know what´s missing or with incompatible version, avoiding copying and trying methods ?
f) Is something missing on the config file ?
Thanks all for any kind of help. This is making me crazy as I´m stuck on that since the beggining of the week...
I'm not sure about the installation options for ODAC in a server environment. I know you need the Transaction module only if you're using TransactionScope in your code.
The problem you're seeing from not being able to find the provider is because Oracle changed the provider name from Oracle.DataAccess.Client to Oracle.ManagedDataAccess.Client with the 12c bits.
You need to change this in both the connection strings and in the SSDL section of the EDMX file: you will go from
<edmx:StorageModels>
<Schema Namespace="Model.Store" Alias="Self" Provider="Oracle.DataAccess.Client" (...)
to
<edmx:StorageModels>
<Schema Namespace="Model.Store" Alias="Self" Provider="Oracle.ManagedDataAccess.Client" (...)

CR with visual studio 2010 logon box

We are using CR with Visual studio 2010 for our applicaton.
Following is the code which I am using for generating the report from collection of objects which I got from Webservice.
SampleReport report = new SampleReport();
report.SetDataSource(response.Items);
Then at WPF level, I am assigning report source to the viewer as follows.
this.reportViewer.ViewerCore.ReportSource = report;
Problem is it is asking me login credential. Which I believe interesting as All the information to generate the report is ready to be picked up from the collection assigned as datasource.
Let me know what these credential could be. or how to override the behaviour.
Note: The designer had designed the .rpt file from xml, that WCF service provided.
I have looked around in forums for solutions, they dont have much information except following :
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
CrystalDecisions.CrystalReports.Engine.Tables CrTables ;
crConnectionInfo.ServerName = "YOUR SERVER NAME";
crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";
crConnectionInfo.UserID = "YOUR DATABASE USERNAME";
crConnectionInfo.Password = "YOUR DATABASE PASSWORD";
CrTables = report.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
The problem is, I can understand if I would be connecting to DB to get the data... But getting data from object collection should not require the credential.
I faced such a problem earlier. What I did to fix this:
In the Visual Studio designer make sure that the Crystal Report Viewer doesn't have a report source defined
In the Crystal Report designer open the Field Explorer and right click on Database Fields and make sure you have selected the correct database location using the Set Database location, also try the Log On or Off Server
This is part of the code to load the report:
rptDoc.Load("CrystalReport_Test.rpt")
rptDoc.SetDataSource(rptDataset)
CrystalReportViewer1.ReportSource = rptDoc
CrystalReportViewer1.RefreshReport()
Hope this helps.

IIS5 - ODBC - Data source name not found and no default driver specified

I’ve got some problem using an ODBC connection with IIS.
Here is my config :
IIS 5 on Windows XP
ASP.NET 2.0
Oracle 9
VS 2005
When I try too use my web application on IIS, I’ve got the following exception:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
BUT, when I use it like a web site in VS2005, I didn’t have any error.
So, I’d try to make a very little app, with the following code:
using System;
using System.Data;
using System.Data.Odbc;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
OdbcConnection con = new OdbcConnection();
con.ConnectionString = "DSN=<MyDSN>;Uid=<LOGIN>;Pwd=<PASSWORD>";
IDbCommand com = new OdbcCommand();
com.CommandText = "select sysdate from dual;";
com.CommandType = CommandType.Text;
com.CommandTimeout = 30;
com.Connection = con;
try
{
con.Open();
Response.Write(com.ExecuteScalar());
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}
}
}
It work fine on VS’s web server (ie: http://localhost:3715/Web/Default.aspx), but I’ve got the same exception (IM002) when I use it on IIS (ie: http://localhost/Tester/default.aspx).
My DSN is declared on the “ODBC Data Source Administrator” and work well when I test the connection…
The ASPNET account is in the same group as my user account (Administrators).
Full right for ASPNET Account on HKEY_LOCAL_MACHINE\SOFTWARE\ODBC and
HKEY_CURRENT_USER\Software\odbc keys.
I've read this post, but nothing work...
I'd look after an answer on stackoverflow (search, related questions, etc.), google...but I didn't found a working solution...
Is there anyone who have an idea?...
Where is my mistake?...
UPDATE: 2011/04/06
What I’ve done so far:
Tracing for ODBC: on VS’Web server, I got log; but on IIS, none...
System and User DSN are filled with the same information
Allow ASPNET, IUSR_XXX, IWAN_XXX, and all users (sic…) accounts full rights to: %ORACLE_HOME%, HKEY_LOCAL_MACHINE\SOFTWARE\ODBC, HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE
Windows, VS and IIS are all for 32 bits (so, there is no c:\windows\syswow64).
Check PATH value, and put %ORACLE_HOME% first.
IIS was reset each time I do a modification, my computer reboot twice.
But, now, I’ve got this message:
ERROR [IM003] Specified driver could not be loaded due to system error 998 (Oracle dans OraHome92).
And I finally found...
The administrators have install all the drivers in order to be used by the user only...
I’d create a system env var ORACLE_HOME...
There was only a user var :s
Thanks for your help.
I validate the Garry M. Biggs' answer because of the difference between system/user...
Had this problem ..
The best solution is to re install your odbc driver ... worked for me ..
the registry entries in your system might have got tampered .
I did a complete uninstall and re install .. worked for me .. lame but quick solution .
Make sure you have created a System DSN rather than a User DSN.
IIS will be running as a System service and therefore does not have access to User registry entries...
Maybe your system is 64 bit version
of Windows and IIS is 64 bit, but VS
is 32 bit? If so, look at my
answers:
odbc connection string dosen't work on windows 7
If you can connect from one environment and not from the other then enable ODBC tracing and compare log files. MS described it at: http://support.microsoft.com/kb/274551

Resources