Unobtrusive Oracle Deployment on Windows Server 2008 - iis-7

I have a .NET 4.0 Web Forms app that I am running with the beta Oracle EF-aware data provider, and I want to perform "unobtrusive" Oracle deployment to a Win2K8 box, as shown in many SO solutions.
There is an existing Oracle Instant Client installation on the Win2K8 box, which I can neither work with nor remove, and it has an entry in the PATH environment variable on the Win2K8 box. According to this SO answer, I do not need to set PATH for my Oracle DLLs, since I have DllPath set in the web.config.
I am following the procedure from here, yet I still get the provider is not compatible with the version of Oracle client error.
Here's my (unsuccessful) setup, as of now:
Oracle DLLs are in my web app's bin directory, and set to Copy Always Do Not Copy.
Platform and Platform Target settings are set to x86 in my local Build Configuration.
32-bit applications are enabled in the app pool (.NET 4.0) on the Win2K8 box.
Oracle DLLs are not present in the GAC, not are they present in the GAC_32 and GAC_64 directories on the Win2K8 box.
My web.config (but not my Win2K8 machine.config) contains this:
<configuration>
<configSections>
<section name="oracle.dataaccess.client" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<oracle.dataaccess.client>
<settings>
<add name="DllPath" value="C:\inetpub\wwwroot\myapp\bin"></add>
<add name="FetchSize" value="65536"></add>
<add name="StatementCacheSize" value="10"></add>
<add name="TraceFileName" value="c:\temp\odpnet2.log"></add>
<add name="TraceLevel" value="0"></add>
<add name="TraceOption" value="0"></add>
</settings>
</oracle.dataaccess.client>
<system.data>
<!-- Version=4.112.2.50 -->
<DbProviderFactories>
<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=4.112.2.50, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=Oracle.DataAccess.Client;provider connection string="DATA SOURCE=**<using EZCONNECT format here>**" providerName="System.Data.EntityClient" />
</connectionStrings>
<configuration>
The app itself deploys successfully, and I can run pages that do not reference my Oracle DLLs. But, for those that do reference Oracle, I still get the provider compatibility error.
What am I missing?
Thanks again for the help.
UPDATE: The web app runs on the Win2K8 target with .NET 4.0, EF4.1, and the Oracle EF Provider, completely separate from the other active ODAC install. No PATH variable, no installation from Universal Installer, no Oracle DLLs in GAC.

Case closed. I was missing an Oracle DLL.

Related

Issue EntityFramework 5.0.0 connection with oracle 11g

I am using EntityFramework 5.0.0 and my db is oracle11g client 12c Oracle Database (ODP.NET, Managed Driver) Version 12.1.My Database is already exists so i am calling existing tables and i connected my db using edmx its connected fine, But i am not using edmx in my actual application so i coded 1 entity and its configuration by hand, now its not connecting i think my connection string is wrong my web.config code is you can see connection string below
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<connectionStrings>
<add name="dbContext" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string="DATA SOURCE=xxx;PASSWORD=aaa;PERSIST SECURITY INFO=True;USER ID=aaaa"" providerName="System.Data.EntityClient" />
</connectionStrings>
Please tell me solution.
Thanks
below is my connection string which fixed connectivity issue.
<add name="dbContext" connectionString="DATA SOURCE=yourdatasource;PASSWORD=xxx;PERSIST SECURITY INFO=True;USER ID=abc;" providerName="Oracle.ManagedDataAccess.Client" />
Make sure you are using EF 5.0.0 and ODAC 64-bit(if your machine is 64 bit) ODAC 12c Release 2 (12.1.0.1.2) Xcopy for Windows x64
Thanks

Problems with EF 4.3 when deployed

I have EF4.3.1 installed on my local machine.
I created a new web application project and added the framework. I then created a database/model etc. The framework is split over 2 projects 1 DAL, 1 Entities. On my local machine I'm restricted to SQL Express 2008.
Here is the configuration section from web config:
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
Here is the connection string I use:
<add name="PayDayLoanEntities" connectionString="metadata=res://*/Models.PayDayLoans.csdl|res://*/Models.PayDayLoans.ssdl|res://*/Models.PayDayLoans.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQLEXPRESS;attachdbfilename="C:\Documents and Settings\John\My Documents\Visual Studio 2010\Projects\IL\WebSite\App_Data\PayDayLoans.mdf";integrated security=True;connect timeout=30;user instance=True;multipleactiveresultsets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
All this works!
On my production machine I use SQL 2008 web edition so, changed the connection string as follows:
<add name="PayDayLoanEntities" connectionString="metadata=res://*/Models.PayDayLoans.csdl|res://*/Models.PayDayLoans.ssdl|res://*/Models.PayDayLoans.msl;provider=System.Data.SqlClient;provider connection string='Data Source=localhost;Initial Catalog=PayDayLoans;uid=***;pwd=********";integrated security=True;connect timeout=30;user instance=True;multipleactiveresultsets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
However, I get the following error message:
Could not load file or assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
The config section refers to 4.3.1 but the error 4.1.0. Anyone know what I'm missing here?
Any help appreciated.
There's a good chance that something in your solution is referencing EF 4.1.0 when built for RELEASE. Perhaps you have a build server that is not updated properly?
Run Fuslogvw (as Administrator or it will silently fail) on your production machine. Start logging bind failures before you start your web application. Fuslogvw will tell you what exactly tried to bind EF 4.1.0.

Entity Framework works on Local Server but not Remote

Ok so I have a website that uses ASP.net mvc, the problem I am having is with Entity Framework. I added all the references and got it to run on my local machine but when I publish it I get the following error.
System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' for the 'System.Data.SqlClient' ADO.NET provider could not be loaded. Make sure the provider assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
I have double checked my references and I have EntityFramework.SqlServer and System.Data both added into my project. The connection string I use to connect to the data base and declare the service provide is below.
<connectionStrings>
<add name="[dataConnection]" connectionString="Data Source=[ip of host machine];Database=[name];UID=[user];pwd=*******;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
Name we just have the name of the data base, this is also used in my web.debug.config
<connectionStrings>
<add name="[dataconnection]"
connectionString="Data Source=.;Database=[name];UID=[user];pwd=*******;MultipleActiveResultSets=True;"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
I am pretty new to this entire thing and was just handed someone elses code so I am trying to learn on the flow. This is my first encounter with this so any direction would be appreciated.
I had the same problem in my integration test assembly (i'm using ms visual studio unit testing framework for this) and i've solved it by adding EF assemblies to deployment items in .testsettings file.
I've installed EF 6 alpha using Package Manager Console using:
Install-Package EntityFramework -Pre
Here is my app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
My connection string (i'm setting it in code): server=.\SIN;initial catalog=IntegrationTests;User ID=user;Password=pass;MultipleActiveResultSets=true;
I've looked at the EF assembly reference properties to see if they are set to "Copy Local" = True.
And finally i've checked out TestResults/../Out folder and found that there is no EntityFramework.SqlServer assembly there (SqlProviderServices class resides in it).
So i've just added both EF 6 assemblies to my deployment items and now everything is ok
You can try to copy EntityFramework.SqlServer assembly to your web server directory to see if it works.
Maybe this link can be helpful
P.S:
Make sure you don't have a reference to System.Data.Entity, because you'll be using one from GAC. EF 6 Alpha assemblies is not installed in GAC when you install them with Nuget. Target framework should be .NET 4.5.
Sorry for my bad english.
A question: which EF version?
Check your IIS pool .NET version... It should be the one that points to the .NET version of your published project... The assembly of EF should be in the .NET framework folder under Windows directory (AKA GAC)

System.Data.SQLite and SubSonic 3: Works great in VS2008, but not in VS2010

Last year, I used SubSonic 3 and SQLite in a VS2008 project very successfully and was quite pleased with the results. Just recently, I tried to setup SubSonic 3 and SQLite in a VS2010 project and have been met with the inner exception when trying to instantiate a new SimpleRepository:
The type initializer for
'System.Data.SQLite.SQLiteFactory'
threw an exception
Just to make sure I wasn't going crazy, I tried the exact same code and app.config file in VS2008 and no problem. Weird!
Currently, I'm using SubSonic 3.0.0.4 and the x64 version of System.Data.SQLite 1.0.73.0 (3.7.6.3) (though I tried the 32 bit version as well.) I added both DLLs as a Reference and set "Copy Local" to TRUE.
My App.Config looks like:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="myDatabase" connectionString="Data Source=C:\DB\mydatabase.db3" providerName="System.Data.SQLite"/>
</connectionStrings>
And my code looks like:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SubSonic.Repository;
namespace SubSonicSqliteTestConsole
{
class Program
{
static void Main(string[] args)
{
var repo = new SimpleRepository("myDatabase", SimpleRepositoryOptions.RunMigrations);
}
}
}
Any ideas?
I am using SubSonic 3 with Visual Studio 2010 and SQLite 1.0.66 and it works.
However there are a few things you have to do:
Your application has to be x86 (not AnyCPU) or you get a BadImageFormatException on 64 bit machines
You have to change the Target Framework from "Framework 4.0 Client Profile" to "Framework 4.0"
You have to add (or modify) this to your app.config file. SQLite won't work without the useLegacyV2RuntimeActivationPolicy flag set to true
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
My Factory initialisation code looks like this (it includes the Version and the PublicKeyToken). I got this settings from the machine.config file on my dev machine where I ran the setup and have choosen to integrate SQLite to Visual Studio 2010 (from the All Programs\SQLite folder). The file is located # %WinDir%\Microsoft.NET\Framework\<FrameworkVersion>\CONFIG
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite"
description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</DbProviderFactories>
</system.data>
My connection strings contains slashes instead of backslashes in the path and contains a version
<connectionStrings>
<add name="connectionstringname"
connectionString="Data Source=c:/temp/mydatabase.db;Version=3;"
providerName="System.Data.SQLite"/>
</connectionStrings>
Hope that helps.
Update:
I see you use a x64 version of SQLite, so forget about the first hint. But I leave it, maybe it is helpful for others.
If I remember correctly, the "The type initializer for ... threw an exception" error message usually means that something in the static constructor for the type threw an exception. You might want to try opening System.Data.SQLite.SQLiteFactory in Reflector or dotPeek or JustDecompile or whatever tool you prefer, and see what its static constructor (.cctor) is doing. Do you have ti using .NET 4 in VS2010 and .NET 2/3 in VS2008? That might be part of the issue too.

Encrypting externally stored App blocks with exportable Key Provider

I have been trying for quite a while to figure out how to encrypt Application blocks that are stored in an external file called dev_entlib.config
I can see in entlib (4.1) that it's possible to use the default protection providers to encrypt the blocks but, I really need to deploy this Application on different servers and thus I would need to export the keyProvider used to encrypt the application blocks to those servers.
What I've done so far is to add a custom Protected Configuration Provider to the machine.config file in the .net v2.0* whatever folder (and all the target servers)
the custom provider is like this
<add name="MyCompanyProvider"
type="System.Configuration.RsaProtectedConfigurationProvider,
System.Configuration, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a,
processorArchitecture=MSIL"
keyContainerName="MyKey"
useMachineContainer="true" />
that sits nicely beside the other default providers and even has design time support in the Entlib config tool. I then choose the protection provider for each block I want to encrypt.
Looking at the dev_entlib.config, shows that indeed the block was encrypted with my provider. My provider uses my key container. Therefore the block should be encrypted using my key container. I then Export "MyKey" to an xml file using:
c:\Windows\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis.exe -px "MyKey" "C:\keys.xml" -pri
Exporting RSA Keys to file...
Succeeded!
This key file is then copied to my sysTest server where it is imported and has access rights granted to "NT Authority\Network Services" and "ASPNET"
I then copy over my encrypted web.config and dev_entlib.config and try to display the connection strings in a small page which uses .net ConfigurationManager to get the ConnectionStrings collection and display them on the page. This page is running under IIS and the identity of the process is "NT Authority\Network Services".
The problem is, that it doesn't work! There are bad data errors or "failed to decrypt using provider MyCompanyProvider".
This approach seems to make logical sense to me but it still fails.
Does anyone have another suggestions?
Encrypt external Enterprise Library configuration files with your custom RSA key container using the Enterprise Library Configuration tool.
EntLib (4.1) uses the default protection provider RsaProtectedConfigurationProvider. But it is possible to remove this provider within your configuration file and replace it with your own with the same name which can then point to your custom key provider: "MyKey".
You should add this configProtectedData section in the configuration file that has the region that you want to encrypt (e.g. your external file: *dev_entlib.config*). You do not need to modify the machine.config file at all.
You can then choose the RsaProtectedConfigurationProvider from the Enterprise Library Configuration application for the Data Access Application Block ProtectionProvider.
You have to open this EntLibConfig.exe with Run as administrator if you are on Vista, Windows 7, Windows 2008.
Otherwise you will get an error:
Failed to encrypt the section 'connectionStrings' using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: Object already exists.
You can then copy this encrypted *dev_entlib.config* along with the web.config configuration file to your sysTest server. Open up the web.config file with Enterprise Library Configuration tool on that sysTest server should not get the error:
Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: Bad Data.
web.config
This file is pretty much empty and just points to the external Data Configuration file:
<!-- web.config -->
<configuration>
<configSections>
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<enterpriseLibrary.ConfigurationSource selectedSource="External Data Configuration File Source">
<sources>
<add name="External Data Configuration File Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
filePath="dev_entlib.config" />
</sources>
</enterpriseLibrary.ConfigurationSource>
</configuration>
dev_entlib.config
This file has the connection strings and the protection provider with which it should be encrypted with:
<!-- dev_entlib.config -->
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<dataConfiguration defaultDatabase="MyConnectionStringName" />
<connectionStrings>
<add name="cnHnicMediaLibrary" connectionString="Server=MyDbServer; Database=MyDbName; Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
</connectionStrings>
<configProtectedData>
<providers>
<remove name="RsaProtectedConfigurationProvider" />
<add name="RsaProtectedConfigurationProvider"
keyContainerName="MyKey"
useMachineContainer="true"
description="Uses our own encryption key container so that it will work in a Web Farm setting. We need to trick Enterprise Library, which wants to use the default RsaCryptoServiceProvider to encrypt and decrypt, by replacing this default provider with our own while this configuration is processed!"
type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</configProtectedData>
</configuration>
Based on:
http://entlib.codeplex.com/discussions/237555 (AvanadeSupport, Dec 8 2010 at 11:37 PM)
http://entlib.codeplex.com/discussions/10300 (shane2007, Jul 9 2007 at 1:15 PM)
http://entlib.codeplex.com/discussions/213998 (need to change the version back to 2.0.0.0)
I hope that this described the error message that you had and how to fix it.
It doesn't seem to be possible yet. My solution is to just encrypt the blocks as part of the web.config and then copy and paste those blocks into an external entLib.config file. These block should then be able to be decrypted on the target servers with the exported key.

Resources