ReflectionTypeLoadException in Simple.Data using PostgreSql - asp.net

I am trying to open PostgreSQL connection but getting ReflectionTypeLoadException while opening connection.
Please help me out to solve this problem by providing code or let me know how to remove this exception.
Code i am using so far is below:
**/* Connection String
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="superuserDatabase" value="postgres"/>
</appSettings>
<system.data>
<DbProviderFactories>
<clear/>
<add name="Npgsql Data Provider"
invariant="Npgsql"
description=".Net Framework Data Provider for Postgresql Server"
type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="Simple.Data.Properties.Settings.DefaultConnectionString"
connectionString="host=localhost;port=5432;database=SimpleData;user id=postgres;password=P#ssw0rdsa;pooling=false"
providerName="Npgsql" />
<add name="Test"
connectionString="host=localhost;port=5432;database=SimpleData;user id=postgres;password=P#ssw0rdsa;pooling=false"
providerName="Npgsql" />
</connectionStrings>
</configuration>**
*/
I am getting following exception when trying to open connection in POSTGRESQL
var namedDb = Database.OpenNamedConnection("Test").Demo.All();
ReflectionTypeLoadException

This ReflectionLoadTypeException is most often caused because the DLLs you're using aren't up to date so the dependency chain fails. Use nuget to update your project with the latest DLLs. v0.16.2.2 of the PostgreSql provider requires
Simple.Data.Core (≥ 0.12.2.2)
Simple.Data.Ado (≥ 0.12.2.2)
Npgsql (≥ 2.0.11)
(via Mark Rendle) Try explicitly installing 0.16.2.2 of Simple.Data.Ado first, then installing the Postgres package.

Related

connect asp.net with postgreSQL

I am tryig to connect my asp.net project to a postgres database.
My webconfig file:
<configuration>
<connectionStrings>
<add name="con" connectionString="Driver={PostgreSQL};Server=localhost;Port=5432;Database=demo;Uid=postgres;Pwd=postgres; "/>
</connectionStrings >
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>
my connection code:
using (NpgsqlConnection connection = new NpgsqlConnection())
{
connection.ConnectionString = ConfigurationManager.ConnectionStrings["con"].ToString();
It is throwing error:
Could not load file or assembly 'Mono.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. The system cannot find the file specified.
How to solve this?
I also have install postgres odbc driver and created a system dsn. If Possible How to use that?
Please check the link below :
http://bytes.com/topic/postgresql/answers/778355-using-npgsql-net

Oracle.ManagedDataAccess: TNS:could not resolve the connect identifier specified

I'm getting the following error while trying to connect to an Oracle database from a new ASP.NET MVC 4 application: "ORA-12154: TNS:could not resolve the connect identifier specified". I'm using the Oracle.ManagedDataAccess DLL (version 4.121.1.0) to try to connect to an Oracle 10g database. Here's the thing - I have an integration test assembly that is successfully connecting to the database using this minimal App.config:
<connectionStrings>
<add name="OracleConnection" connectionString="DATA SOURCE=TNS_NAME;PASSWORD=xxx;PERSIST SECURITY INFO=True;USER ID=xxx" providerName="Oracle.ManagedDataAccess.Client" />
</connectionStrings>
However, if I try to run my web app with all the crazy Web.config settings, I'm getting the error "ORA-12154: TNS:could not resolve the connect identifier specified". What am I doing wrong? Why is my config for the integration test assembly so simple and the Web.config so complex? Here's the pertinent sections of my Web.config (taken from Deploying and Configuring ODP.NET to work without installation with Entity Framework):
custom configSection:
<configSections>
<section name="oracle.manageddataaccess.client"
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</configSections>
the corresponding config section:
<oracle.manageddataaccess.client>
<version number="*">
<edmMappings>
<edmMapping dataType="number">
<add name="bool" precision="1"/>
<add name="byte" precision="2" />
<add name="int16" precision="5" />
</edmMapping>
</edmMappings>
</version>
</oracle.manageddataaccess.client>
custom system.data node:
<system.data>
<DbProviderFactories>
Remove in case this is already defined in machine.config
<remove invariant="Oracle.DataAccess.Client" />
<remove invariant="Oracle.ManagedDataAccess.Client" />
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client"
description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
EntityFramework node:
<entityFramework>
<defaultConnectionFactory type="Victoria.Data.OracleConnectionFactory, EntityFramework" />
</entityFramework>
Update 1: After reading through http://docs.oracle.com/cd/E16655_01/win.121/e17732/featConfig.htm#ODPNT8161, I tried modifying my Web.config oracle.manageddataaccess.client to the following and it works. However, it doesn't seem right to have the connectionString node referencing the TNS name AND this extra reference to the same TNS Names file.
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="SIEBMATS" descriptor="(DESCRIPTION=(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.yyy.zzz)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = siebmats)))" />
</dataSources>
<edmMappings>
<edmMapping dataType="number">
<add name="bool" precision="1"/>
<add name="byte" precision="2" />
<add name="int16" precision="5" />
</edmMapping>
</edmMappings>
</version>
</oracle.manageddataaccess.client>
One thing you can try is having the connection string like so:
connectionString="Data Source=//SERVER:PORT/INSTANCE_NAME;USER=XXX;PASSWORD=XXX".
Useful references here:
http://www.connectionstrings.com/oracle/
http://docs.oracle.com/cd/E51173_01/win.122/e17732/featConnecting.htm#ODPNT169
This has also helped me while having problems with EF:
Deploying and Configuring ODP.NET to work without installation with Entity Framework
Hope to have helped.
My problem was in incorrect/incomplete Oracle Driver version, had 11.2.0 installed. I add another 12.2.0 version, didn't change anything in web.config and it worked as charm
I suggest to try the solution proposed by #kolbasov in another thread but about the same problem: https://stackoverflow.com/a/20050462/9390179
It worked for me:
<oracle.manageddataaccess.client>
<version number="*">
<settings>
<setting name="TNS_ADMIN" value="C:\Oracle\product\11.1.0\client_1\network\admin" />
</settings>
</version>
</oracle.manageddataaccess.client>

ASP.NET and MySQL .Net Framework Data Provider Issues

I'm new in ASP.NET. Everytime I try to run my application, I encounter the error message below. I already installed .Net Framework Data Provider for MySQL several times.
I hope someone can help me on this. Thanks in advance.
Server Error in '/PLDT QuickSearcher' Application.
Unable to find the requested .Net Framework Data Provider. It may not be installed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
Add MySql.Data.dll as reference to the project
Add this block to web.config:
<system.data>
<DbProviderFactories>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory,MySql.Data" />
</DbProviderFactories>
</system.data>
Reference the MySql.Data and MySql.Entities Nuget packages. Then add this line to your web config.
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
Your connection string should be similar to the following:
<add name="MyDb" connectionString="Server=127.0.0.1;Port=3306;Database=MyDb;Uid=root;Pwd=;" providerName="MySql.Data.MySqlClient" />
I have solved this problem with following configuration
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider"
invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
</DbProviderFactories>
</system.data>
<entityFramework>
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>

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.

Enterprise library 4 dataconfiguration tag

I am using Enterprise library for my data access.
When I am running the application, at the CreateDatabase() statement I am getting this exception:
Microsoft.Practices.ObjectBuilder2.BuildFailedException
was unhandled by user code
Message="The current build operation
(build key Build
Key[Microsoft.Practices.EnterpriseLibrary.Data.Database,
null]) failed:
The value can not be null or an empty string.
(Strategy type Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy,
index 2)"
Source="Microsoft.Practices.ObjectBuilder2"
Now, I googled a bit and I found that I have to place
<dataConfiguration defaultDatabase="LocalSqlServer"/>
but I don't know where. Is it the right solution?
Also, at the time of installing enterprise library I didn't see any connection string statement? So, I wonder how it will take the connection string from web.config file.
In the connection string section of my web.config file I have:
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=MSTR;Initial Catalog=USERDb;Integrated Security=true;" providerName="System.Data.SqlClient"/>
Yes you need to add the dataConfiguration section to the web.config.
First you need to add dataConfiguration to the list of ConfigurationSections in your web.config:
<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>
Then you need to add your connection strings to the web.config (you've already done this):
<connectionStrings>
<add name="LocalSqlServer" connectionString="Data Source=MSTR;Initial Catalog=USERDb;Integrated Security=true;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Then you need to add the actual dataConfiguration section to the web.config:
<dataConfiguration defaultDatabase="LocalSqlServer"/>
You can also use the Enterprise Library Configuration Tool to do this for you as well.

Resources