Using SQL Server CE 4 on a remote host with MVC 3 - asp.net-mvc-3

I just upgraded my host to MVC 3 but I'm trying to do a "hello world" using SQLCE 4.0 but I just got:
Sorry, an error occurred while
processing your request.
I see my layout and everything but instead of data I see that.
On localhost is working as expected
I have:
<add name="PruebaContext" connectionString="Data Source=|DataDirectory|db.sdf" providerName="System.Data.SqlServerCE.4.0"/>
as connectionString.
I put the sdf as part of the project, I added the System.Data.SqlServerCE.dll to the project with the local copy to true.
I have no more ideas. The connString, the dll is in /bin and is working in localhost.
Any ideas?
Thanks.
EDIT
I have some logs now:
Without the "System.Data.SqlServerCE.dll" on /bin:
Unable to find the requested .Net Framework Data Provider. It may not be installed.
System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
Fine enough. They don't have SqlServerCE4.
With the Dll on local copy, AKA /bin:
Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8482. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.
Exception Details: System.Data.SqlServerCe.SqlCeException: Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8482. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.
The KB says that I need the dll from x86 and amd64. I read somewhere that if I copy two directories to /bin, like: /bin/x86 and /bin/amd64 . I copied that folders from the private folder of SqlServerCE 4 installation folder. Now I got:
Possible file version mismatch detected between ADO.NET Provider and native binaries of SQL Server Compact which could result in an incorrect functionality. This could be due to the presence of multiple instances of SQL Server Compact of different versions or due to wrong binaries with same name as SQL Server Compact binaries. Please install SQL Server Compact binaries of matching version.
Ok. On the root folder of SQLServerCE4 I have some dlls too, so I deleted that two folders and copied that dll to /bin:
Could not load file or assembly 'file:///C:\HostingSpaces\jesusrod\foxandxss.net\wwwroot\mvc3\bin\sqlceca40.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
I think that I tried all things. Scottgu said that SqlServerCE 4 should work on any server without installation.

I don't like to respond to my own answer, but after hours of work I have the answer!
We need:
NuGet (Better than copying the dll's from program file)
With NuGet we install:
EFCodeFirst
SqlServerCompact
EFCodeFirst.SqlServerCompact
The problem was that EF need another dll for SQL CE 4 (System.Data.SqlServerCe.Entity.dll) and we need to put some configuration on web.config:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
With that, all is working. I have seen like 5 different errors, so we need:
The 2 dll from SQL CE 4, the EF dll, the config in web.config and the native dll (from the package directory where NuGet downloads the library).
It seems that the web.config config is pointing to a concrete version of the SQL CE .dll and the version of the RTM package is different. I can't find the concrete version so I use the .dll from NuGet.
That's all, SQL CE 4 + EF on a remote host.

Just use menu "Project/Add Deployable Dependencies..."
I'm not sure if it is Visual Studio 2010 SP 1 only.

You need to make sure you have the native SQL CE 4.0 dlls in your private application directory (e.g. \bin) in addition to the managed one.
Copy them from "C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Private\amd64" (or x86 if you have a 32-bit app).
It may also be wise to deploy the MSVCR90.dll and it's manifest too. Have a look at the documentation in C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0
for more information about the required DLLs and redistribution.

This looks like a problem that's caused by having multiple intermediate bits of data left in a project, where you've replaced included files without cleaning up.
I'd recommend doing a Build->Clean all, followed by making sure that all of your references are to the new, correct DLLs, and then making sure that none of the old files or references are still around anywhere in your project. Attempt to rebuild once that is done.
Since this is a hello world project, it might be easier to just start from scratch with a new project, and include the correct dlls in there.

try installing SQL CE manually.
http://www.microsoft.com/download/en/details.aspx?id=17876
Good Luck.

I was having the same problem. Trying to put a code-first SQL CE 4.0 app into play on my goDaddy account.
I started messing around with various DLL files based upon the thread above and other tutorials, but nothing seemed to work. Something was missing. Then I read about the Add Deployable Dependencies response.
I did that, which created _bin_deployableAssemblies folder. Then I deleted everything from my bin folder except my core project's DLL and copied everything from _bin_deployableAssemblies into the bin folder.
I cleaned out everything in the bin folder on my goDaddy app and resynced the files. That worked. The app loads and if I make codefirst changes to the classes, the dbcontext recreates the database for me. Of course, I don't want that in production, but I wanted to know that everything was working.
I did try using the ASP tutorial about deploying an MVC app to a hosting environment (they use Cytanium hosting as their example), but it didn't work for me on GoDaddy. I had to copy files manually.
Thanks all. This was a huge step for me being able to feel comfortable continuing in MVC and EF.

Related

Oracle Entity Data Model(ODP.NET)

We are trying to create an Entity Data model (edmx) file using Database first approach for Oracle Db.( We already have a running version of edmx for SQL Server).
Installed ODP.NET package which includes Oracle.ManagedDataAccess.dll and Oracle.ManagedDataAccess.EntityFramework.dll in Visual studio 2017 for Framework 4.5 via Nuget Packages
Manually modified the connection string for Oracle as
<connectionStrings>
<add name="FacetsDataModel"
connectionString="metadata=res://*/EntityDataModel.csdl|res://*/EntityDataModel.ssdl|res://*/EntityDataModel.msl;provider=System.Data.OracleClient;provider connection string=”Data Source=***;User Id=**;Password=***;”;" providerName="Oracle.ManagedDataAccess.Client" />
</connectionStrings>
The above approach didn't work because we found out that we are missing ODP.Net Managed Provider in the system. So we tried installing ODT Tools for Visual Studio 2013(didn’t work) uninstalled the same and installed 2017(still the same issue)
We found out that we missed ODAC (Oracle Data Access Components), so we installed the same but still, we didn't get the ODP.Net Managed Data Provider.
We checked the machine.config file from the below path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config
When we tried searching for a solution, we got the below link ODP.NET Managed - Unable to find requested.Net Framework Data Provider
Point 11 -- They have mentioned modifying the machine.config file by including ODP.NET, Managed Driver Under section. After modifying the machine.config file, our visual studio got crashed.
As mentioned in the link, we checked with Registry key file and check if RegKey exists or not.
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft.NETFramework\v4.0.30319\AssemblyFoldersEx\odp.net.managed
A managed ODP.NET driver does not show up in Data Source dialogue
But in our system, there is no such folder exists named AssemblyFoldersEx in the specified path.
You missed several information, for example what is in your config file machine.config. Also you did not provide us any error message. Statements as "The above approach didn't work" are not very helpful.
Anyway I will try to give you some hints:
ODAC (Oracle Data Access Components) is a collection of various providers (ODP.NET managed and unmanaged, ODBC, OLE DB). Perhaps you selected the wrong component while installation.
HKLM\SOFTWARE\Wow6432Node\Microsoft.NETFramework\v4.0.30319\AssemblyFoldersEx\odp.net.managed is not used anymore. Usually the installation script should have deleted it. You Registry should look like this:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v2.0.50727\AssemblyFoldersEx\ODP.Net]
#="c:\\oracle\\product\\12.2\\odp.net\\bin\\2.x"
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319\AssemblyFoldersEx\ODP.Net]
#="c:\\oracle\\product\\12.2\\odp.net\\bin\\4"
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319\AssemblyFoldersEx\Oracle.ManagedDataAccess]
#="c:\\oracle\\product\\12.2\\odp.net\\managed\\common"
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319\AssemblyFoldersEx\Oracle.ManagedDataAccess.EntityFramework6]
#="c:\\oracle\\product\\12.2\\odp.net\\managed\\common\\EF6"
Of course you have to set folders according to your system.

Visual Studio 2013, Firebird and Entity Framework

I still cannot use EF with Firebird in VS2013 pro and Win7 pro !
Here's what I have done :
I have created a new class library for my dal project, and imported the ef6 and the firebird provider via nuget like said in this page http://www.nuget.org/packages/FirebirdSql.Data.FirebirdClient-EF6/
Then I copied the fb provider to some place and use gacutil to register it into the cache:
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil -i fibirdprovierpath
Please note that I used the gacutil from the netfx4.5.1 (don't know if it change something)
After that I grabbed the ddex dlls, put them somewhere, change the regfiles that came with (32/64), for the path and ran them.
I have also modified the machine.config (32/64) to reference the Firebird provider .
Now, I can add a Firebird connection without any problem in the servers window, I can even create a Winforms pp that uses a Firebird dataset, BUT when I want to add an .edmx model, the Firebird option is unavailable, I have only SQL Server.
Make sense to anyone please !!!
Is this not related to your problem? http://tracker.firebirdsql.org/browse/DNET-522
i finally fugured out how to fix that !
with the registry files there is another subfolder named withSDK and it was empty,
so i searched for an older ddex files , edited the registry files that are located in that withsdk folder and voila !

Could not load file or assembly "Oracle.DataAccess" or one of its dependencies

I am trying to run this web application. I keep getting this error
"Could not load file or assembly "Oracle.DataAccess" or one of its dependencies. An attempt was made to load a program with an incorrect format."
Exception details: System.BadImageFormatException. "Could not load file or assembly "Oracle.DataAccess" or one of its dependencies. An attempt was made to load a program with an incorrect format."
Below are the things that I already tried.
replaced all the oracle dll's with 32 bit oracle dll i.e 2.112.3.0
I have 32 bit client installed on 64 bit machine. The operating system is windows 7.
compile each individual project individually. Deleted all the oracle dependent files dll and then added the 2.112.3.0 dll's individually and then compiled each project
Register the 32 bit dll on GAC using this statement
gacutil /i %ORA_HOME4%\odp.net\bin\4\Oracle.DataAccess.dll
gacutil /i %ORA_HOME4%\asp.net\bin\4\oracle.web.dll
for the above two statements, I copied the gacutil.exe from c:\Program Files(x86)\Microsoft sdk\windows\v7.0A\Bin\NETFX4.0 Tools\X64
to C:\ drive and then
I executed the above two statement:
gacutil /i %ORA_HOME4%\odp.net\bin\4\Oracle.DataAccess.dll
gacutil /i %ORA_HOME4%\asp.net\bin\4\oracle.web.dll
when I executed the above two statements, I didn't get any message, I executed them in Dos windows under administrator privilege.
I also deleted all the Temporary ASP.net files from this location
c:\windows\Microsoft.Net\V4.0.30319\temporary ASP.net files
I also changed the web application build Platform target to X86, Originally, it was at "ANy CPU". out of frustration, I also tried changing the platform target to X64 and then I got the error message saying
" Cold not load file or assemble . webapp" or one of its dependencies. An attempt was made to load a program with an incorrect format.
I don't have IIS installed on my computer, I am running this application in visual studio 2010 so I think it will be using the inbuilt IIS that comes with visual studio.
I spend lot of hours resolving this issue, but still getting the same error again and again.
Try this: Open IIS Manager, change application pool's advance setting, change Enable 32 bit Application to false.
I found the solution with following steps:
remove the Oracle.DataAcces.dll reference,
and add a fresh reference to:
C:\windows\assembly\GAC\Oracle.DataAccess\X.XXX.X.XX__89b483f429c47342/oracle.dataaccess.dll
Make local copy= false.
Hope it helps
You may need to enable 32-bit applications in your AppPool.
Go to > 'Application Pool' in IIS => right click your app pool => advance setting => 'enable 32 bit application' to true.
Please don't forget to restart your app pool and your corresponding application pointing to that app pool.
If you are using IIS Express and VS 2017:
Go to the Web Application Properties > Web Tab > Servers Section > And change the Bitness to x64.
Had the issue again when i moved from one machine to another and had everything reinstalled. In my case, i'm using both 32bit and 64bit Oracle ODP.NET installs.
When listing the assemblies on my new machine i ended up with the following list
C:\oracle\product\11.2.0\X64\odp.net\bin\4>gacutil /l|findstr Oracle.DataAccess
Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64
Policy.2.102.Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64
Policy.2.111.Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64
Policy.2.112.Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64
Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64
Policy.4.112.Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64
only 64bit DLLs to be seen here.
I couldn't see it from the web.config but the one i was using was a 32bit version.
When checking my old machine with the GACutil, i saw more DLLs, also the X86 ones.
Fixed by reapplying the registration process(both x32/x64 version referenced here)
OraProvCfg.exe /action:gac /providerpath:C:\oracle\product\11.2.0\x32\ODP.NET\bin\4\Oracle.DataAccess.dll
OraProvCfg.exe /action:gac /providerpath:C:\oracle\product\11.2.0\x64\ODP.NET\bin\4\Oracle.DataAccess.dll
after that , Visual Studio was a happy bunny and compiled everything again for me.
I had the same error with Oracle.DataAccess but deploying to Azure Web Sites (azurewebsites.net). For me I had to edit a setting in VS.NET 2019 before publishing to Azure. I ticked the checkbox "Use the 64 bit version of IIS Express for Web sites and projects" which is found under Tools > Options > Projects and Solutions > Web Projects.
In my case the following solved the problem:
Downloading the "32-bit Oracle Data Access Components (ODAC)
with Oracle Developer Tools for Visual Studio" from http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html
Then adding reference oracle.dataaccess.dll to the bin file by browsing the file location or just from the refence list in .NET tab.
In my case, I use VS 2010, Oracle v11 64 bits. I might to publish in 64 bit mode (Setting to "Any Cpu" mode in Web Project configuration) and I might set IIS on Production Server to 32 Bit compability to false (because the the server is 64 bit and I like to take advantage it).
Then to solve the problem "Could not load file or assembly 'Oracle.DataAccess'":
In the Local PC and Server is installed Oracle v11, 64 Bit.
In all Local Dev PC I reference to Oracle.DataAccess.dll (C:\app\user\product\11.2.0\client_1\odp.net\bin\4) which is 64 bit.
In IIS Production Server, I set 32 bit compatibility to False.
The reference in the web project at System.Web.Mvc.dll was the version v3.0.0.1 in the local PC, however in Production is only
instaled MVC version 3.0.0.0. So, the fix was locallly work with MVC
3.0.0.0 and not 3.0.0.1 and publish again on server, and it works.
Also you can download and execute the install.bat file in 'ODAC112030Xcopy.zip' from 64-bit Oracle Data Access Components (ODAC) Downloads. This resolved my problem.
For me everything else was almost ok, but somehow my project settings changed & iisExpress was getting used instead of IISLocal. When I changed & pointed to the virtual directory (in IISLocal), it stared working perfectly again.
I needed a 64-bit version of oracle.dataaccess.dll but this caused problems with other libraries I was using.
[BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
I followed several steps above. Going to advance settings on the projects pool to toggle allow 32bit worked but I wasn't content to leave it like that so i turned it back on.
My project also had references that relied on Elmah and log4net references.
I downloaded the latest version of these and my project was able to build and run fine without messing with the pools's allow 32bit setting.
i Have face the same issue and resolved by replacing the old Oracle.DataAccess.dll with new Oracle.DataAccess.dll(which come with oracle client when install)
in my case the path of new Oracle.DataAccess.dll is
E:\app\Rehman.Rashid\product\11.2.0\client_1\ODP.NET\bin
In my case I had a console application, I just unchecked Prefer 32-bit on Build projet properties tab and then I add this to my app.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="2.112.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

Oracle.DataAccess 2.112.1.0 reference issues in .NET4.0 VS2010

I have an Oracle.DataAccess 2.112.1.0 version referenced in my project. Whenever I run the project I get an error Could not load the assembly. I checked the entries made in the .csproj file for the referenced dll, and found that the referenced dll was Oracle.DataAccess 2.111.7.0. I am pretty sure the referenced dll is Oracle.DataAccess2.112.1.0 but not sure why the entry made in the project file is different. Any pointers to this would be helpful as this issue has been holding me up for a long time.
I found the same issue when a client use 2.112.1.0 in their references, but it kept referencing a machine local 2.112.3.0.
The reason is that when installed in the GAC, it inserts a policy file - a GAC level config entry to redirect your DLL to their newer version. Even if you have the file in the same dir, .NET 2+ will check the GAC for any policies before allowing your application to resolve the assembly itself.
Something I tried was a manual redirection in your App/Web.config file, but I found this didn't work for me, which is detailed under Redirecting Assembly Versions.
Once this is done, you may encounter this issue:
BadImageFormatException - Image is not of correct format (or something similar)
and/or
Version mismatch - The major/minor version does not match (or something similar)
These errors indicate that although your older assembly is now in use, the COM assemblies it reference are not expected. My investigation found Oracle ODP.NET assemblies stores its COM DLL versions hard-coded within.
The only solution that did for me, was to
Un-GAC the 2.112.X.0 that your app was auto-referencing.
Copy the version specific COM DLLs to a different directory (like \LIB)
Copy them into the build, as you build
If this all fails, I would recommend completely uninstalling the Oracle ODP.NET, deleting the Oracle directory manually and then after rebooting, installing the old DLL from the MSI directly. Oracle seem to have stored the whole history of drivers online at Oracle's website.
Good luck!

Migrating SQL CLR project from VS2008 to VS2010 - deploy fails

I have a solution with a SQL CLR project in VS2008. The solution / project was converted to VS2010 and now the deploy no longer works.
I get the following type of erros:
Beginning deployment of assembly MyProjectDatabaseCode.dll to server DEVPN-004 : MyProject
The following error might appear if you deploy a SQL CLR project that was built for a version of the .NET Framework that is incompatible with the target instance of SQL Server: "Deploy error SQL01268: CREATE ASSEMBLY for assembly failed because assembly failed verification". To resolve this issue, open the properties for the project, and change the .NET Framework version.
C:\inetpub\wwwroot\VS2010_MyProjectSolution\DatabaseCode\bin\Release\MyProjectDatabaseCode.dll : Deploy error : Plan verification encountered errors; deployment cannot continue.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.SqlClr.targets(96,5): Deploy error TSD00561: This deployment may encounter errors during execution because changes to [dbo].[Column1] are blocked by [dbo].[Table1].[Column1]'s dependency in the target database.
I verified and the project is targeted against .NET 3.5. We have predeployscript.sql and postdeployscript.sql files that are supposed to be run. It appears like they are not being run by VS2010. What could be causing the issue?
We ended up contacting Microsoft and they reproduced our issue as a known bug. They offered a workaround by retargeting the assembly to .NET 2.0, but that didn't work in our scenario either.
It seems that the only way forward until the fix is to create a brand new SQL CLR project in 2010 and add all the files to it by hand.
I'd recommend using Reflector to take a look at your assembly in the build output directory. If you see 2 references to mscorlib, then what has happened is that a phantom reference to the 4.0 framework has been added to the project. If you see this problem, you may be able to get rid of the 4.0 reference by hand editing your project file. Open the project in an XML editor, and look for the following line:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="2.0">
Change ToolsVersion="2.0" to ToolsVersion="4.0"
This helped me with a similar upgrade problem, but your mileage may vary. If you don't see the phantom mscorlib reference, you probably have another issue.
I've seem this problem consistently when I renamed some objects or somehow the target database got out of sync, that is, some objects were not dropped and Deploy was trying to recreate them.
I managed to fix it by running a cleanup script (drop objects/assemblies) from MS Server Management Studio and verifying that no old objects remained in the Database.
It's a try/error experience but you can try first to deploy to another server/database and if it succeeds, chances are you have some garbage in the target database, that's how I came to the conclusion for I was able to deploy to another database.

Resources