Spring.net, AOP causing properties not to be set - c#

I'm new to C# but exp in Spring in Java. I can reproduce my problem quiet easily using the Spring example project Spring.WcfQuickStart.2010.
In the Spring.WcfQuickStart.ServerApp.2010 project do the following
1) Add the following TestDI class.
namespace Spring.WcfQuickStart
{
public class TestDI
{
public int test { get; set; }
public TestDI()
{
this.test = 10;
Console.WriteLine("TestDI cons called, value set to {0}", test);
}
}
}
2) In CalculatorService.cs, return "ServerApp Calculator testDI value=" + tdi.test;
3) In App.config do the following.
<object id="testObj" type="Spring.WcfQuickStart.TestDI, Spring.WcfQuickStart.ServerApp" singleton="true"/>
<object id="calculator" singleton="true"
type="Spring.WcfQuickStart.CalculatorService, Spring.WcfQuickStart.ServerApp">
<property name="tdi" ref="testObj"/>
<property name="SleepInSeconds" value="1"/>
</object>
Now, if you run the program you would expect that the client would be returned the value 10 but I am getting the value 0. This is the same for any property I define. If the TestDI properties test is changed to be static, same issue.
The only way to prevent this and get the value 10 is to remove the following from the App.config file.
<object id="serviceOperation" type="Spring.Aop.Support.SdkRegularExpressionMethodPointcut, Spring.Aop">
<property name="pattern" value="Spring.WcfQuickStart.*"/>
</object>
I could also just change the value="Spring.WcfQuickStart.*" to be something else but then I have no aspects for my code.
Any help greatly appreciated.

Try setting your properties as 'virtual'. I have found that if the properties are not virtual when working with AOP, often you will see null/default values.

The reason for this is explained in section 13.6 of the Spring.NET documentation: http://www.springframework.net/doc-latest/reference/html/aop.html#aop-proxy-mechanism. Sounds like you are using the inheritance-based mechanism.

Related

NHibernate mapping error ([EntityName] not mapped)

My project (c#, nhibernate, npgsql, nlog) has one entity named Entry and should be mapped to the database table named test. Table contains some test entries.
My application code is as follows:
public void work()
{
ISessionFactory sessions = new Configuration().Configure().BuildSessionFactory();
ISession session = sessions.OpenSession();
IList<Entry> entries = session.CreateQuery("from Entry").List<Entry>();
foreach (Entry e in entries)
{
logger.Debug("Entry: " + e.id + " with " + e.name);
}
}
The Entry entity looks like this:
namespace pgsql
{
class Entry
{
public virtual int id { get; set; }
public virtual string name { get; set; }
}
}
My NHibernate configuration is structured as below:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
<property name="dialect">NHibernate.Dialect.PostgreSQLDialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="default_catalog">test</property>
<property name="default_schema">test</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<property name="connection.connection_string">server=localhost;database=*****;uid=*****;pwd=*****;</property>
</session-factory>
</hibernate-configuration>
The Entry entity configuration is as follows:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping schema="test" xmlns="urn:nhibernate-mapping-2.2">
<class name="Entry" table="test">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
</class>
</hibernate-mapping>
This throws below error:
Entry is not mapped [from Entry]
I have made sure, that Visual Studio is copying all hbm.xml files to the output directory. What am i missing?
Edit in response to your answer:
the solution was to initialize with the Assembly:
ISessionFactory sessions = new Configuration().Configure().AddAssembly(Assembly.GetExecutingAssembly()).BuildSessionFactory();
but i still don't know, why it has to be like that.
I will explain why it has to be like that.
Your entity is defined in same assembly as that of your application.
When you call Configuration().Configure().BuildSessionFactory(), actually all your HBM files are being ignored. You need to do either of following to add HBM file to Configuration instance:
Use new Configuration().AddFile("MyFile.hbm.xml") for each individual HBM file.
Use new Configuration().Configure().AddAssembly(YourAssembly()) to tell NHibernate to look for all HBM files and add all those for you.
Other ways mentioned in document linked below.
As you was not doing either of this, there were no entity configurations added to Configuration. Whey you try to run your HQL query, NHibernate was looking for Entry entity which was not defined (added to Configuration). Hence was the error.
As you mentioned in your answer, you choose second way to add HBM files to Configuration and issue went away.
Another alternative (probably the best) way is to let NHibernate load all of the mapping files contained in an Assembly:
Configuration cfg = new Configuration()
.AddAssembly( "NHibernate.Auction" );
Then NHibernate will look through the assembly for any resources that end with .hbm.xml. This approach eliminates any hardcoded filenames and ensures the mapping files in the assembly get added.
Please refer doc for more details.
Original Answer
Entity name should include namespace as well.
IList<Entry> entries = session.CreateQuery("from pgsql.Entry").List<Entry>();
To make refactoring bit easy, you may also change to something like following:
var queryString = string.Format("from {0}", typeof(Entry));
IList<Entry> entries = session.CreateQuery(queryString).List<Entry>();
Please refer section 14.2. The from clause from docs.
Not a part of your problem but, call to BuildSessionFactory is costly. You do not need to repeat it. You can call it at the startup of your application may be and maintain the instance of ISessionFactory for future use.
the solution was to initialize with the Assembly:
ISessionFactory sessions = new Configuration().Configure().AddAssembly(Assembly.GetExecutingAssembly()).BuildSessionFactory();
but i still don't know, why it has to be like that.

The mapping of CLR type to EDM type is ambiguous with EF 6 & 5?

Please any one can help me to fix this error?
Schema specified is not valid. Errors:
The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'City_DAL'. Previously found CLR type 'CeossDAL.City_DAL', newly found CLR type 'CeossBLL.City_DAL'.
The main problem that I have DAL and this contains the EF and BLL and this contains the same classes of the DAL but differ in the namespace and this is what cause the problem
I can't know how to get rid of these problem, can you please help me?
Also I will be appreciated if some one give me sample to use n-tier architecture with EF
Thank you
Don't use classes with the same unqualified name - EF uses only class names to identify the type mapped in EDMX (namespaces are ignored) - it is a convention to allow mapping classes from different namespaces to single model. The solution for your problem is to name your classes in BLL differently.
Workaround: Change a property on one of the two identical classes.
EF matches on class name AND class properties. So I just changed a property name on one of the EF objects, and the error is gone.
As #Entrodus commented on one of the other answers:
EF collision happens only when two classes have the same name AND the
same set of parameters.
This MSDN forum question might be helpful. It suggest placing the BLL and DAL classes in separate assemblies.
In some cases this is more of a symptom than the actual problem. For me, it usually pops up when I try to call a function inside a Linq query without calling .ToList() first.
E.g. the error that brought me here was caused because I did this:
var vehicles = DB.Vehicles.Select(x => new QuickSearchResult()
{
BodyText = x.Make + " " + x.Model + "<br/>"
+ "VIN: " + x.VIN + "<br/>"
+ "Reg: " + x.RegistrationNumber +"<br/>"
+ x.AdditionalInfo
type = QuickSearchResultType.Vehicle,//HERE. Can't use an enum in an IQueryable.
UniqueId = x.VehicleID
});
I had to call .ToList(), then iterate through each item and assign the type to it.
For EF 6.x, I found some notes at https://github.com/aspnet/EntityFramework/issues/941 and fixed this in my solution by adding annotation to the EDM type.
I edited the EDMX file manually and changed a line like this:
<EntityType Name="CartItem">
to this:
<EntityType Name="CartItem" customannotation:ClrType="EntityModel.CartItem">
or use this if you have existing type elsewhere:
<EntityType Name="CartItem" customannotation:ClrType="MyApp.CartItem, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
where EntityModel is the namespace used for my EF model, and MyApp is the namespace of a business object
I got the error above because for both connection strings, I had the same value for metadata specified in my main project's config file, like below:
<add name="EntitiesA" connectionString="metadata=res://*/EntitiesA.csdl|res://*/EntitiesA.ssdl|res://*/EntitiesA.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=MyDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="EntitiesB" connectionString="metadata=res://*/EntitiesA.csdl|res://*/EntitiesA.ssdl|res://*/EntitiesA.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=MyDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
I ended up copying the correct connection string from the EntitiesB's project's config file.
This may not have been available when the question was asked, but another solution is to delete the EDMX and recreate it as a code-first entity data model. In EF6, with code-first, you can map two classes with the same name from different model namespaces without creating a conflict.
To create the entity data model in Visual Studio (2013), go to "Add" > "New Item..." > "ADO.NET Entity Data Model". Be sure to choose the "Code First from database" option.
Another reason you might get this error:
If you're loading custom assemblies with Assembly.LoadFile that have edmx files, that have already been loaded into memory. This creates duplicate classes that entity framework doesn't like.
For me this was because I was attempting to access a type with the same name on the wrong context instance.
Say both ContextA and ContextB have SomeType. I was trying to access ContextA.SomeType on an instance of ContextB.
Just add the EntityFramework as "Code First from database" and not as "EF Designer from database". This resolved my problem, but it has a dark side, if you change your database you have to remove all the classes and add it again, or just edit the classes, I use the last when I change properties of the columns, like "Allows null" or the size of a string. But if you add columns I recomend remove and add again the classes.
I was able to solve this issue without renaming the classes, properties, or metadata.
I had my project setup with a T4 transform creating entity objects in a DAL project, and a T4 transform creating domain objects in a Domain project, both referencing the EDMX to generate identical objects, and then I was mapping the DAL objects to the Domain objects.
The error only occurred when I was referencing other classes (enums in my case) from the Domain assembly in my queries. When I removed them, the error went away. It looks like EF was loading up my Domain assembly because of this, seeing the other identically named classes, and blowing up.
To resolve this, I made a separate assembly that only contained my T4 transformed Domain classes. Since I never need to use these inside a query (only after the query to map to), I no longer have this issue. This seems cleaner and easier than the answers below.
if you have 2 connection string in web config but you want to use one connection string
You use dynamic create connection string other entities.
I have edmx(db first) and code first Entities in my solution.
I use this class in Code first entities.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity.Core.EntityClient;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Data
{
public class SingleConnection
{
private SingleConnection() { }
private static SingleConnection _ConsString = null;
private String _String = null;
public static string ConString
{
get
{
if (_ConsString == null)
{
_ConsString = new SingleConnection { _String = SingleConnection.Connect() };
return _ConsString._String;
}
else
return _ConsString._String;
}
}
public static string Connect()
{
string conString = ConfigurationManager.ConnectionStrings["YourConnectionStringsName"].ConnectionString;
if (conString.ToLower().StartsWith("metadata="))
{
System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder efBuilder = new System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder(conString);
conString = efBuilder.ProviderConnectionString;
}
SqlConnectionStringBuilder cns = new SqlConnectionStringBuilder(conString);
string dataSource = cns.DataSource;
SqlConnectionStringBuilder sqlString = new SqlConnectionStringBuilder()
{
DataSource = cns.DataSource, // Server name
InitialCatalog = cns.InitialCatalog, //Database
UserID = cns.UserID, //Username
Password = cns.Password, //Password,
MultipleActiveResultSets = true,
ApplicationName = "EntityFramework",
};
//Build an Entity Framework connection string
EntityConnectionStringBuilder entityString = new EntityConnectionStringBuilder()
{
Provider = "System.Data.SqlClient",
Metadata = "res://*",
ProviderConnectionString = sqlString.ToString()
};
return entityString.ConnectionString;
}
}
}
And when I call entities
private static DBEntities context
{
get
{
if (_context == null)
_context = new DBEntities(SingleConnection.ConString);
return _context;
}
set { _context = value; }
}
I Think u Have a Class X named "MyClass" in Entity Models and Another Class Called "MyClass" in the same WorkFolder or Extended of the first Class.
That is my problem and i fix it.
I found that using the custom annotation solution works with EF 6.2.0. Just make sure to change in the ConceptualModels node and use full namespace for the type.
<edmx:ConceptualModels>
<Schema Namespace="Sample.Access.Data.Ef" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityType Name="DbTableName" customannotation:ClrType="Sample.Access.Data.Ef.DbTableName, Sample.Access.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<Key>
<PropertyRef Name="DbTableNameId" />
</Key>
<Property Name="DbTableNameId" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Name="OptionName" Type="String" MaxLength="100" FixedLength="false" Unicode="false" Nullable="false" />
<Property Name="Value" Type="String" MaxLength="500" FixedLength="false" Unicode="false" Nullable="false" />
<Property Name="UpdatedDate" Type="DateTime" Nullable="false" Precision="3" />
</EntityType>
<EntityContainer Name="MyEntities" annotation:LazyLoadingEnabled="true" customannotation:UseClrTypes="true">
<EntitySet Name="DbTableNames" EntityType="Self.DbTableName" />
</EntityContainer>
</Schema>
</edmx:ConceptualModels>
There is a library called AutoMapper which you can download. It helps you to define class mappings from one type to another.
Mapper.CreateMap<Model.FileHistoryEFModel, DataTypes.FileHistory>();
Mapper.CreateMap<DataTypes.FileHistory, Model.FileHistoryEFModel>();

Making WPF navigation dynamic - using an XML file?

I'm working on the navigation part of a desktop application, and have a bit of a problem. The request is that the navigation should be dynamic, so that you can, for instance, switch orders of the views without having to recompile (and ideally also adding a view without recompiling).
Currently I'm using an XML to define which windows to display, which header it should have and how the footer should look like. Here's how the XML looks now:
<?xml version="1.0" encoding="utf-8" ?>
<ArrayOfViewState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ViewState ViewName="WelcomeView" Header="Welcome to the Application" FooterButton1="Quit" FooterButton2="Back" FooterButton3="Next" />
<ViewState ViewName="LicenseView" Header="Licence Agreement" FooterButton1="Quit" FooterButton2="Back" FooterButton3="Next" />
<ViewState ViewName="LoginView" Header="Log in" FooterButton1="Quit" FooterButton2="Back" FooterButton3="Next" />
<ViewState ViewName="InstallationView" Header="Installing..." FooterButton1="Cancel" FooterButton2="None" FooterButton3="Next" />
<ViewState ViewName="UpdateView" Header="Updating..." FooterButton1="Cancel" FooterButton2="None" FooterButton3="Next" />
<ViewState ViewName="FinishedView" Header="Finished!" FooterButton1="None" FooterButton2="None" FooterButton3="Finish" />
</ArrayOfViewState>
And when I match this in the code it looks like this (viewState.View is of type UserControl):
...
case "WelcomeView":
viewState.View = new WelcomeView();
...
As you can see I use the ViewName property in the XML to match and create my views (they also have a ViewModel, but that is taken care through XAML and the MVVM Light ViewModel Locator).
This solution technically allows the navigation to be changed somewhat without recompiling (for example you can shuffle the order any way you like), but there must be a better way to handle this than matching a string property. I've tried looking into serializing the User Control so that I could just load it along with the other properties, but so far I've had no luck. Any ideas on how to go about and improve/change this?
Thanks!
Indeed, there is a better way. :-)
Have a look at the Microsoft Extensibility Framework (MEF). It works very well with WPF and MVVM.
It allows you to easiliy compose application parts on-the-fly during runtine.
In short, you mark a class you want to be loaded somewhere else with an Attribute [Export]:
[Export(typeof(ViewContainer))]
public class ViewContainer
{
public string ViewName = "WelcomeView";
public string Header="Welcome to the Application"
// Do more stuff here
}
And in the class or assembly that should use the exported class you can load it with the [Import] Attribute:
public class ClassInOtherAssembly
{
[ImportMany]
internal ObservableCollection<ViewContainer> m_MyViews { get; set; }
// Do other stuff here
}
Depending on the architecture that you implement it might even be sufficient to use a 1-liner (!) to assemble all imported classes (this uses a different approach than the following referenced tutorial):
CompositionInitializer.SatisfyImports(this);
And that's it!
(Do not take these examples as is, I just wanted to get to the point. I recommend using
Properties instead of the strings and interfaces instead of the class export. You'll find plenty of more elegant snippets on the net. :-) )
Here you can find a tutorial to get you started:
Getting started with Managed Extensibility Framework (MEF)
Why not use reflection?
You could use Activator.CreateInstance and pass in your View's string:
string asmName = "YourAssembly";
string typeName = "YourViewName";
object obj = Activator.CreateInstance(asmName, typeName).Unwrap() as UserControl;

NHibernate unable to create SessionFactory

I'm having a bit of trouble setting up NHibernate, and I'm not too sure what the problem is exactly. I'm attempting to save a domain object to the database (Oracle 10g XE). However, I'm getting a TypeInitializationException while trying to create the ISessionFactory. Here is what my hibernate.cfg.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="MyProject.DataAccess">
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">
User ID=myid;Password=mypassword;Data Source=localhost
</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.OracleDialect</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<mapping resource="MyProject/Domain/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
I created a DAO which I will use to persist domain objects to the database. The DAO uses a HibernateUtil class that creates the SessionFactory. Both classes are in the DataAccess namespace along with the Hibernate configuration. This is where the exception is occuring. Here's that class:
public class HibernateUtil
{
private static ISessionFactory SessionFactory = BuildSessionFactory();
private static ISessionFactory BuildSessionFactory()
{
try
{
// This seems to be where the problem occurs
return new Configuration().Configure().BuildSessionFactory();
}
catch (TypeInitializationException ex)
{
Console.WriteLine("Initial SessionFactory creation failed." + ex);
throw new Exception("Unable to create SessionFactory.");
}
}
public static ISessionFactory GetSessionFactory()
{
return SessionFactory;
}
}
The DataAccess namespace references the NHibernate DLLs. This is virtually the same setup I've used with Hibernate in Java, so I'm not entirely sure what I'm doing wrong here. Any ideas?
Edit
The innermost exception is the following:
"Could not find file 'C:\Users\Tyler\Documents\Visual Studio 2010\Projects\MyProject\MyProject\ConsoleApplication\bin\Debug\hibernate.cfg.xml'."
ConsoleApplication contains the entry point where I've created a User object and am trying to persist it with my DAO. Why is it looking for the configuration file there? The actual persisting takes place in the DAO, which is in DataAccess. Also, when I add the configuration file to ConsoleApplication, it still does not find it.
It is looking for the configuration file in that directory because that is the default location for NHibernate to look for a configuration file. Note that this is a directory, it has nothing to do with namespaces. You need to set the properties on the hibernate.cfg.xml file in your project to copy to output directory.
I think this issue will be resolved if you can copy the cfg.xml file to the folder that contain the NHibernate assembly

Fluent NHibernate - exception occurred during configuration of persistence layer

I am using Fluent NHibernate with an external 'hibernate.cfg.xml' file.
Following is the configuration code where I am getting error:
var configuration = new Configuration();
configuration.Configure();
_sessionFactory = Fluently.Configure(configuration)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Template>())
.BuildSessionFactory();
return _sessionFactory;
But When NHibernate is trying to configure, I am getting floowing error:
An exception occurred during configuration of persistence layer.
The inner exception says:
The ProxyFactoryFactory was not configured.
Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.
I googled and according to some solutions I found, I have made following changes:
Add following dlls to my app bin:
Castle.Core.dll, Castle.DynamicProxy2.dll, NHibernate.ByteCode.Castle.dll
Added follwing property in hibernate.cfg.xml
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
But still I am getting the same exception.
I had this error too. It fires when you don't copy the mapping file (hibernate.cfg.xml) to the build directory.
Solution:
In Solution explorer, right click on the mapping file (hibernate.cfg.xml), choose Properties, then make sure that Copy To Output Directory has Copy if newer selected).
As Alex InTechno said, this might be the error in the definition of your Mapping files or in mapped entities. I experienced the same error, when I have forgot that all properties in mapped classes have to be defined as virtual.
public String Name {get;set;}
public virtual String Name { get; set; }
The problem might be in your hibernate.cfg.xml, double check that is using 2.2 version and if well formed.
The mapping should start like this:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
Along with the error you post, maybe more information is supplied because that error is quite generic to the configuration parser. If not, maybe you can give more details of your hibernate.cfg.xml.
Exception with the text of PotentialReasons
* Database was not configured through Database method.
might be also thrown by the FluentConfiguration.BuildConfiguration() method in the case your mappings are wrong (i.e. .*Map classes were not successfully parsed) and you have configured database not with .Database() method.
This is a bit confusingly that it is discovered only at the step of building configuration, not when these classes are being added from assembly (by AddFromAssemblyOf<>)
You can check whether your *Map classes are successfully converted to HBM by executing a line
m.FluentMappings.Add(typeof(YourMappedTypeMap)).ExportTo(#"c:\Temp\fluentmaps"))
I had the same issue with NUnit tests under Resharper 8.1
Tick "ReSharper | Options | Tools | Unit Testing | Use separate AppDomain for each assembly with tests" checkbox fixed it
Well, I was able to resolve that error by placing .cfg.xml file in bin of calling app.
But now, I am getting another error :-(
FluentNHibernate.Cfg.FluentConfigurationException was unhandled
Message: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
* Database was not configured through Database method.
Here is my hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=dev\sql2005;Initial Catalog=TestDB;Integrated Security=True</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
Any thoughts?
Trying to configure the database in App.config and the mappings via Fluent NHibernate, I also got a FluentNHibernateException saying
Database was not configured through Database method.
The link to show details was deactivated, so I couldn't get any further information. Searching for hours I finally found out that my connection string had an error ("pasword=xyz;" instead of "password=xyz;")
Try to set modifier protected in set_id and set_sampelList. for example:
public virtual int Id {
get; protected set;
}
and
public virtual IList<Store> StoresStockedIn {
get; protected set;
}
I begin receiving the
* Database was not configured through Database method.
error message while attempting to connect to a DB/2 database without having made any changes to my code. After verifying that the configuration file was being copied to the build directory and verifying that my XML was well-formed and conformed to version 2.2, I finally went to check the database to ensure that nothing had changed.
It turned out that the password for the connecting account had expired. It wasn't invalid nor was the account inactive--the password was merely expired. I am not sure why the expired password manifested in such an odd error message.
It seems like this error can be a bunch of different things. I got the same error and eventually figured out it was because I had excluded an unused view and mapping from the project. No idea how this was causing the error but as soon as I added it back the error was gone.

Categories

Resources