I have problem with my ASP.NET MVC app which is using SQLSERVER 2012 Expresss for security and somehow this is conflicting with my Firebird installation which is not used in this case. Getting exception like this:
An error occurred creating the configuration section handler for system.data: Column 'InvariantName' is constrained to be unique.
Value 'FirebirdSql.Data.FirebirdClient' is already present.
I have tried to enter in my web.config this:
<remove invariant="FirebirdSql.Data.FirebirdClient"/>
but that didn't work, what I have finally do I have removed this firebird entry from machine.config:
<system.data>
<DbProviderFactories>
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient, Version=3.0.2.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c"/><add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient, Version=3.0.2.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c"/></DbProviderFactories>
and that worked out, but th is not ideal solution bcause I still need firebird to use sometimes. Anyway to disable this entry temporarily in app web,config? Also, why I am getting such conflict to start with anyway?
thanks
You have the same record in machine.config twice. Remove one and you'll be fine.
I have a similar problem and ended up with a different solution.
What happen is that I started developing my Web application in the default (root) folder IIS creates.
After that, for testing purposes I changed this option to work in a deeper folder in the same domain:
I added the name and clicked "Create Virtual Directory". The application ran but gave me the similar problem.
What happen is that when I created the second virtual directory IIS express leave the first one there pointing to the same location. So I have the same app twice sharing Web.config hierarchically.
Solution to my problem
To solve this I just changed the port so the previous created virtual directory is not my root anymore.
Related
I'm trying to to work with Entity Framework 6, and connect it to a Postgresql
database.
I'm using npgsql.Entityframework, but get an error when creating the ddex file.
Can someone knows why?
Thanks.
Install Npgsql, to work between Entity Framework to PostgreSql:
Download and install the Setup_NpgsqlDdexProvider.exe from https://github.com/npgsql/npgsql/releases.
Open Visual-Studio, click on the tab: TOOLS -> Setup Npgsql DbProviderFactories.
A window will open, you need to click OK.
Close Visual-Studio and open as administrator the two machine.config files of .NET with notepad.
There are two file that we need to edit, you can find the file at the paths:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config
Add the flowing element to the files:
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql"/>
<add name="Npgsql Data Provider"
invariant="Npgsql"
description=".Net Data Provider for PostgreSQL"
type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"
support="FF" />
</DbProviderFactories>
</system.data>
Reopen Visual-Studio at the wanted project.
Install Entity Framework through Nuget.
Open the Package Manager Console and insert the commend:
Install-Package EntityFramework6.Npgsql
Check that the wanted DLL are references, like so:
If not add the DLL manually. The sopose to be at the paths:
C:\Users\YOURCOMPUTERNAME\documents\visual studio 2015\Projects\PostgreSqlVsEfwDemo\packages\Npgsql.3.0.5\lib\net45\Npgsql.dll
C:\Users\ YOURCOMPUTERNAME\documents\visual studio 2015\Projects\PostgreSqlVsEfwDemo\packages\EntityFramework6.Npgsql.3.0.5\lib\net45\EntityFramework6.Npgsql.dll
Open the App.config\Web.config and add two elements:
The provider element at entityFramework -> providers. as so:
The provider element at DbProviderFactories. as so:
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql" />
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
</DbProviderFactories>
If the <system.data> element isn't exist, add it all.
Now lets add Entity Data Model like so:
Select "EF Designer from database"
Click on "New Connection"
Choose the "PostgreSQL Database" as the Data source:
Filled the fields:
HOST
USERNAME
PASSWORD
PORT
DATABASE (fill this field last.)
Click on "Test Connection" to see if it works.
Continue with Entity Framework as regular.
Hope it's help you.
This document of Npgsql Docs really helped me, but still have problems.
I read this post which apparently solves the issue with WPF app publishing which has SQL Server Compact dependency. I went through all the steps prescribed by the author of this post but it just doesn't work for me. Once I add all the DLLs from SQL Server Compact "private" folder my app crashes on startup. The difference is that I use .NET 4.5 while the example deals with 4.0 I am not sure if that is the core of the problem but it just doesn't work with those settings.
My app is crashing with the following exception :
System.Windows.Markup.XamlParseException
Here is my app.config (including add on from the article ) :
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="TypeAppRelease.Properties.Settings.MyDatabase_1ConnectionString"
connectionString="Data Source=D:\XXXXXX\XXXXX\XXXXXXX\externals\MyDatabase#1.sdf;Password=XXXXXXX;Persist Security Info=True"
providerName="Microsoft.SqlServerCe.Client.4.0" />
</connectionStrings>
<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.1,
Culture=neutral,
PublicKeyToken=89845dcd8080cc91"/>
</DbProviderFactories>
</system.data>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
One more thing. I came to this because doing just ClickOnce publishing produced installation file which didn't work complaining that
The application is missing required files ....
So that lead me to the solution I linked above which also seems not to work.
Update:
I would like to extend on this problem because until not I haven't resolved it.
I decided to put aside ClickOnce deployment and just test Debug/Release builds on 2 machines:1) With SQL Compact Server installed ;2) Has only NET framework installed.
The App works ok on the first machine and fails on the second.That is pretty logical because the first one has Compact SQL installed and running.
Next I removed the server installation from the first machine and ran the app again.It still works , but not for the second PC .The error I am getting is
System.IO.FileLoadException
I can't figure out why I am getting it and why I am not getting the same on the first machine.
Maybe it is 64 /32 bit OS thing? PC1 runs Windows 7 64bit while PC2 x86.
I you use ADO.NET objects (SqlCeCommand, DataSet) instead of Entity Framework (as described in my blog post) you must reference System.Data.SqlServerCe.dll in your project folder (assembly version 4.0.0.1) and NOT the dll in your GAC (assembly version 4.0.0.0). I have updated my blog post with that information.
I developed a windows application using Entity Framework and as a database, I used SQLite. I have no problem developing it until I add a setup project to my solution to make an installer file for my application and I add .net Framework 3.5 and .net Framework 4.0 and Windows Installer as prerequisite to install.
In other computers, installation is done successfully but when users try to execute the application, they receive this exception
Unable to find the requested .Net Framework Data Provider
I googled this exception and most of the answers talked about provider name tag in web.config. Can anyone help me?
You have to include the System.Data.SQLite.dll provider assembly in your installer package (or make them required in a click-once download app) and then you have to register the provider by adding it to the providers section in the config file.
<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>
I am trying to create a database with SQLite with c# then create a table insert data then close the connection. I have just downloaded System.Data.SQLite.dll lybrary and I am not sure how to use it. There are a lot of examples in the internet but all of them seem to have a database already. Or maybe I am doing something wrong.
It will be nice If I can have a short example to just create a database, table and basic query.
EDIT
I have tried the examples provided by the comments but I don't understand why I do get errors. Maybe I downloaded the wrong library?
The error was because I was using .NET Framework 4.0 . I downgraded to 2.0 and it worked. Sorry for the question. It will be nice to use it with .NET Framework 4.0 though.
Edit:
It actually works with .NET Framework 4.0 I had to add this lines of code to my app.config file:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
also if you plan to use ado.net in your solution I experience a lot of problems when deploying. Everything worked great under development. If you use ado.net and you plan on deploying your app then include also:
<!--Sqlite configuration so that it works with ado.net-->
<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>
if you include that last part in your app.config file then you will have to make sure that:
those dll's have to be in your output directory.
if you deploy make sure that you copy those files to the working directory
shouldnt it be {"FailIfMissing", "False"} instead of {"FailIfMissing=False", "False"} ?
Please change the Platform Target for your C# project to Project Settings > Build > Platform Target: Any CPU.
I had a similar error occurred when i tried to run in a x64 machine with SQLite x64 binaries. But worked fine after these settings were changed
Obviously I'd like to not have to install an Oracle client (other than simply a DLL), because that would prohibit my ClickOnce goal. I tried System.Data.OracleClient, but it threw an exception, "System.Data.OracleClient requires Oracle client software version 8.1.7 or greater."
Update:
It seems that System.Data.OracleClient is not the way to go. So I downloaded the xcopy-able version of the Oracle ODP.NET provider. I then ran "install.bat odp.net20 c:\oracle odac" to install only ODP.NET. Then I added a reference in my project to C:\oracle\odp.net\bin\2.x\Oracle.DataAccess.dll. This allowed me to hit the Oracle DB. But when I take all my files to a clean machine (including the oracle DLL), I get an exception: "The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception." So it seems that it is still depending on some other files. But I don't know what files. And how does it know where the files are? A registry entry? Not looking good for ClickOnce.
Update:
It works as long as I include the files mentioned by mcauthorn: oci.dll, oracle.dataaccess.dll, oraociei11.dll, & oraops11w.dll. Unfortunately, oraociei11.dll is very large -- 114MB.
I would say to go get the ODP.Net Dlls here. You will have to grab the XCopy version, and then add the necessary DLLs to your project and you then should be good to go. The System.Data.OracleClient has been discontinued and is not recommended by Microsoft.
You can use third-party ADO.NET provider. Try this one. It does not require Oracle Client and runs on Mono.
Update, since the original answers are 4 years old.
Just use Oracle's Managed driver. You need only that, nothing else. You can then connect directly with a simple connection string to the database.
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client" />
<!-- If any should be in the machine.config -->
<add name="Oracle Data Provider for .NET" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<clear />
<add name="OracleContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="DATA SOURCE=<IP_ADDRESS>:1521/XE;PASSWORD=<PASSWORD>;USER ID=<USER_ID>;Connection Timeout=600;Validate Connection=true" />
</connectionStrings>
I used ServiceStack's OrmLite as ORM but it should work perfectly fine also directly if you don't want to use an ORM, or with any other. All you need to make sure is that your ORM library is using the managed driver as well and not the old one. I've written a blog post regarding a hack, where I had to change ServiceStack.OrmLite.Oracle to use the new managed driver. This solved all my problems.
Blog post: http://peter.grman.at/how-to-connect-mono-in-linux-to-oracle/
ServiceStack.OrmLite.Oracle.Managed NuGet package: https://www.nuget.org/packages/ServiceStack.OrmLite.Oracle.Managed/
The changes in GitHub: https://github.com/Grman-IT-Solutions/ServiceStack.OrmLite/tree/OracleManagedDataAccess