Is it possible to use MySql or Postgresql in as simple way as it is to use SQL Server with AdoTemplate ?
Or is it necessary to do some additional xml (or other) configuration, e.g. is it necessary to use some Xml file with configuration code, e.g. Spring Dependency Injection xml files ?
This working example below shows how easy it is to use SQL Server with AdoTemplate but without doing any kind of xml configuration:
However, when trying with MySql, then the following code line throws an exception:Code:using System.Data; using NUnit.Framework; using Spring.Data.Common; using Spring.Data.Generic; ... public void TestingSqlServer() { IDbProvider dbProvider = DbProviderFactory.GetDbProvider("System.Data.SqlClient"); dbProvider.ConnectionString = @"Data Source=localhost;Initial Catalog=myExperimentalDatabase; User Id=myUserId; Password=myPassword;"; var adoTemplate = new AdoTemplate(dbProvider); int count = (int)adoTemplate.ExecuteScalar(CommandType.Text, "select count(*) from persons"); Console.WriteLine("count: " + count); }
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("MySql.Data.MySqlC lient");
The exception thrown is the following:
It does not matter whether or not I have MySql.Data connector available within the project references or not.Code:Spring.Objects.Factory.UnsatisfiedDependencyException : Error thrown by a dependency of object 'MySql.Data.MySqlClient' defined in 'assembly [Spring.Data, Version=1.3.2.40943, Culture=neutral, PublicKeyToken=65e474d141e25e07], resource [Spring.Data.Common.dbproviders.xml] line 853' : Unsatisfied dependency expressed through constructor argument with index 2 of type [System.Type] : Could not convert constructor argument value [MySql.Data.MySqlClient.MySqlConnection, MySql.Data, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d] to required type [System.Type] : Cannot convert property value of type [System.String] to required type [System.Type] for property ''. while resolving 'constructor argument with name dbmetadata' to 'Spring.Data.Common.DbMetadata#152C067' defined in 'assembly [Spring.Data, Version=1.3.2.40943, Culture=neutral, PublicKeyToken=65e474d141e25e07], resource [Spring.Data.Common.dbproviders.xml] line 853' at Spring.Objects.Factory.Support.ObjectDefinitionValueResolver.ResolveInnerObjectDefinition(String name, String innerObjectName, String argumentName, IObjectDefinition definition, Boolean singletonOwner) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\ObjectDefinitionValueResolver.cs: line 305 at Spring.Objects.Factory.Support.ObjectDefinitionValueResolver.ResolvePropertyValue(String name, IObjectDefinition definition, String argumentName, Object argumentValue) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\ObjectDefinitionValueResolver.cs: line 151 at Spring.Objects.Factory.Support.ObjectDefinitionValueResolver.ResolveValueIfNecessary(String name, IObjectDefinition definition, String argumentName, Object argumentValue) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\ObjectDefinitionValueResolver.cs: line 113 at Spring.Objects.Factory.Support.ConstructorResolver.ResolveConstructorArguments(String objectName, RootObjectDefinition definition, ObjectWrapper wrapper, ConstructorArgumentValues cargs, ConstructorArgumentValues resolvedValues) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\ConstructorResolver.cs: line 592 at Spring.Objects.Factory.Support.ConstructorResolver.GetConstructorInstantiationInfo(String objectName, RootObjectDefinition rod, ConstructorInfo[] chosenCtors, Object[] explicitArgs) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\ConstructorResolver.cs: line 156 at Spring.Objects.Factory.Support.ConstructorResolver.AutowireConstructor(String objectName, RootObjectDefinition rod, ConstructorInfo[] chosenCtors, Object[] explicitArgs) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\ConstructorResolver.cs: line 95 at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.CreateObjectInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs: line 1000 at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractAutowireCapableObjectFactory.cs: line 940 at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs: line 2086 at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name, Type requiredType) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs: line 1835 at Spring.Data.Common.DbProviderFactory.GetDbProvider(String providerInvariantName) in c:\_prj\spring-net\trunk\src\Spring\Spring.Data\Data\Common\DbProviderFactory.cs: line 94
I have tried with the latest connector version 6.5.4.0, retrieved with nuget, which also is the latest version currently available at http://www.mysql.com/downloads/connector/net/.
The Spring version I am using is also the latest version (1.3.2) which was also retrieved with nuget.
According to the documentation at http://www.springframework.net/docs/...bprovider.html
then the string "MySql.Data.MySqlClient" should be equivalent to be using "MySql-6.2.2" (as far as I understand these strings).
However, since it does not matter whether or not I a referencing any "MySql.Data.dll" in the project or not (i.e. the same error message) I suppose the version is not the problem.
I mean, if only 6.2.2 is supported while I only have the 6.5.4.0 assembly in the project references I would have expected an error message complaining about the version of that dll assembly file.
I have also tried with Postgresql and the following code:
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("Npgsql-2.0");
(with the string "Npgsql-2.0" defined at the Spring 1.3.2 reference page, and I have the latest Npgsql version "2.0.11.0" retrieved with nuget referenced in the project)
gives a similar UnsatisfiedDependencyException message ( ... while resolving 'constructor argument with name dbmetadata' to 'Spring.Data.Common.DbMetadata#1939738' defined in 'assembly ... )
I have also tried with Spring 2.0.0-M1 (instead of 1.3.2) but still get the same problems.
So, please can someone show a minimum working example (with as little required configuration as possible) how you are supposed to use MySql (or postgresql) access with AdoTemplate, and preferably while also being able to use the latest version of the MySql.Data (or postgresql's Npgsql) ADO.NET driver ?


Reply With Quote