Activation error occured while trying to get instance of type Database

Topics: Data Access Application Block
Aug 22, 2012 at 2:45 PM
Edited Aug 22, 2012 at 5:08 PM

Hi,

I am getting the following error "Activation error occured while trying to get instance of type database"

Here is the configuration  

Aug 22, 2012 at 2:47 PM
Edited Aug 22, 2012 at 2:48 PM
dheerajjaggi wrote:

Here is the configuration

<configuration>
	<configSections>
		<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
	</configSections>
	<runtime>
		<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
			<probing privatePath="module;SybaseLib"/>
		</assemblyBinding>
	</runtime>
	<dataConfiguration  >
		<providerMappings>
			<add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Sybase.AseDatabase, Sybase.EnterpriseLibrary.AseClient, Version=4.1.1000.0, Culture=neutral, PublicKeyToken=null"
                name="Sybase.Data.AseClient" />
		</providerMappings>
	</dataConfiguration>
	<connectionStrings>
		<add name="MyConnection" connectionString="**********"
	providerName="Sybase.Data.AseClient" /> 
 </connectionStrings>
	<system.data>
		<DbProviderFactories>
			<add name="Sybase.Data.AseClient"
		   description="Sybase.Data.AseClient" invariant="Sybase.Data.AseClient" type="Microsoft.Practices.EnterpriseLibrary.Data.Sybase.AseDatabase, Sybase.EnterpriseLibrary.AseClient, Version=4.1.1000.0, Culture=neutral, PublicKeyToken=null" />
		</DbProviderFactories>
	</system.data>




</configuration>



 

Aug 22, 2012 at 3:50 PM

What code are you using to resolve the Database?

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Aug 22, 2012 at 5:08 PM



 var defaultDb = EnterpriseLibraryContainer.Current.GetInstance<Database>("MyConnection");

This is what I am using, and added a reference to Sybase.EnterpriseLibrary.AseClient. Should I using some code in order to resolve it ?

Aug 23, 2012 at 6:13 AM

The code looks OK.  I'm wondering if the provider factory is setup properly?  You've added the provider factory which is good but it looks like it's the same class as the providerMapping database type.  I would have expected it to be something like:

<system.data>
    <DbProviderFactories>
        <add name="Sybase.Data.AseClient"
            description="Sybase.Data.AseClient" invariant="Sybase.Data.AseClient" type="Sybase.Data.AseClient.AseClientFactory, Sybase.AdoNet2.AseClient, Version=2.155.1000.0, Culture=neutral, PublicKeyToken=95d94fac46c88e1e" />
    </DbProviderFactories>
</system.data>

I'm not familiar with the AseClient so I'm just guessing at the specific information (assembly name, version, PublicKeyToken) from this document: http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc20066.0215/pdf/adonet2155.pdf.  If you have the bits you should be able to verify the information.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Aug 23, 2012 at 11:59 AM

Thanks Randy,

Now I am getting the following error

The type 'Microsoft.Practices.EnterpriseLibrary.Data.Sybase.AseDatabase, Sybase.EnterpriseLibrary.AseClient, Version=4.1.1000.0, Culture=neutral, PublicKeyToken=null' cannot be resolved. Please verify the spelling is correct or that the full type name is provided.


at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.AssemblyQualifiedTypeNameConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\AssemblyQualifiedTypeNameConverter.cs:line 63
   at System.ComponentModel.TypeConverter.ConvertFrom(Object value)
   at Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DbProviderMapping.get_DatabaseType() in e:\Builds\EntLib\Latest\Source\Blocks\Data\Src\Data\Configuration\DbProviderMapping.cs:line 90
   at Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings.GetDatabaseData(ConnectionStringSettings connectionString, DatabaseSettings databaseSettings) in e:\Builds\EntLib\Latest\Source\Blocks\Data\Src\Data\Configuration\DatabaseSyntheticConfigSettings.cs:line 157
   at Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings.<get_Databases>d__0.MoveNext() in e:\Builds\EntLib\Latest\Source\Blocks\Data\Src\Data\Configuration\DatabaseSyntheticConfigSettings.cs:line 94
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings.<DoGetRegistrations>d__10.MoveNext() in e:\Builds\EntLib\Latest\Source\Blocks\Data\Src\Data\Configuration\DatabaseSyntheticConfigSettings.cs:line 323
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings.GetRegistrations(IConfigurationSource configurationSource) in e:\Builds\EntLib\Latest\Source\Blocks\Data\Src\Data\Configuration\DatabaseSyntheticConfigSettings.cs:line 307
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.TypeLoadingLocator.<GetRegistrations>b__0(ITypeRegistrationsProvider p, IConfigurationSource cs) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\TypeLoadingLocator.cs:line 67
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.TypeLoadingLocator.GetRegistrationsInternal(IConfigurationSource configurationSource, Func`3 registrationAccessor) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\TypeLoadingLocator.cs:line 90
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.TypeLoadingLocator.GetRegistrations(IConfigurationSource configurationSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\TypeLoadingLocator.cs:line 67
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.CompositeTypeRegistrationsProviderLocator.<GetRegistrations>b__0(ITypeRegistrationsProvider l, IConfigurationSource cs) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\TypeRegistrationsProvider.cs:line 128
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.CompositeTypeRegistrationsProviderLocator.<>c__DisplayClass5.<GetRegistrationsInternal>b__4(ITypeRegistrationsProvider l) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\TypeRegistrationsProvider.cs:line 147
   at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator.RegisterAllCore(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\Unity\UnityContainerConfigurator.cs:line 61
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ChangeTrackingContainerConfigurator.RegisterAll(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\ContainerModel\ChangeTrackingContainerConfigurator.cs:line 66
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.ConfigureContainer(ITypeRegistrationsProvider locator, IContainerConfigurator configurator, IConfigurationSource configSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 83
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.ConfigureContainer(IContainerConfigurator configurator, IConfigurationSource configSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 62
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer(IConfigurationSource configurationSource) in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 122
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 108
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 95
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.get_Current() in e:\Builds\EntLib\Latest\Source\Blocks\Common\Src\Configuration\EnterpriseLibraryContainer.cs:line 36
   at Sybase.Program.Main(String[] args) in C:\Architecture\MdxExtractor\Sybase\Sybase\Program.cs:line 77
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Aug 23, 2012 at 1:51 PM

Is the Sybase.EnterpriseLibrary.AseClient.dll located in your application's bin directory or in the GAC?

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Aug 23, 2012 at 1:54 PM

Its located in the Application bin's directory

Aug 23, 2012 at 2:01 PM
I tried adding a reference to  Sybase.EnterpriseLibrary.AseClient.dll  and now it gives me the following error
Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I have the following assembly Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, but I think its trying to locate Enterprise.Data which have PublicKeyToken = null.


Aug 23, 2012 at 2:11 PM

Hi Randy

Here is some additional information if it can help you to trouble shoot the issue.

I used the following configuration and it works in development box where Sybase Open Client is installed. I think it uses Generic Database.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<configSections>
		<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
	</configSections>
	<runtime>
		<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
			<probing privatePath="module;SybaseLib"/>
		</assemblyBinding>
	</runtime>	
	<connectionStrings>
		<add name="MyConnection" connectionString="******"
	providerName="Sybase.Data.AseClient" /> 
 </connectionStrings>
</configuration>
But it fails on the production box where Sybase Open Client is not installed. I am open to use Generic database if that can help me. 
One more thing I noticed is that if I use the native library code without using Enterprise library then it works both on Production and Dev, like for eg.
using (var conn = new AseConnection(connection))
        {
            conn.Open();
            using (var cmd = new AseCommand("sp_get_data", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    var inParam = new AseParameter("@entity", AseDbType.VarChar, 32)
                                      {
                                          Direction = ParameterDirection.Input,
                                          Value = "value"
                                      };
                    cmd.Parameters.Add(inParam);
                    try
                    {
                        return cmd.ExecuteReader(CommandBehavior.CloseConnection);
                        
                      
                    }
                    catch (AseException ex)
                    {
                        System.Console.WriteLine(ex.Source + " : " + ex.Message + " (" + ex.ToString() + ")", "Execute Stored Precedure failed.");
                    }
                }
        }
Thanks
Aug 23, 2012 at 2:17 PM

Is the type name (Microsoft.Practices.EnterpriseLibrary.Data.Sybase.AseDatabase) correct?  

Does this code work?

type = Type.GetType(
    "Microsoft.Practices.EnterpriseLibrary.Data.Sybase.AseDatabase, Sybase.EnterpriseLibrary.AseClient, Version=4.1.1000.0, Culture=neutral, PublicKeyToken=null", true);

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Aug 23, 2012 at 2:23 PM

Returned me the following error, If I added a reference for Sybase.EnterpriseLibrary.AseClient.dll .

Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

 

 

 

Aug 23, 2012 at 8:00 PM

It looks like the assembly that contains the AseDatabase is compiled against a non-signed build of Enterprise Library 4.  But your application is using Enteprise Library 5.

Can you recompile the assembly against Enterprise Library 5?

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Aug 24, 2012 at 8:19 AM

I don't have the source code for the library therefore can't recompile, is there anything else I can do.