I want to try a simple example with Active Record + MSSQL2012. Here is my App.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<startup>
</startup>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect, NHibernate</property>
<property name="connection.connection_string_name">Server=(local);initial catalog=DemoDB;Integrated Security=SSPI</property>
</session-factory>
</hibernate-configuration>
</configuration>
Locally I have a very simple database DemoDB with 3 tables, I've connected to if via SQL Management Studio.
Employee class:
using Castle.ActiveRecord;
namespace ActiveRecordDemo.Domain { [ActiveRecord] public class Employee : ActiveRecordBase { [PrimaryKey] public int Id { get; set; }
[Property] public string FirstName { get; set; } [Property] public string LastName { get; set; } [BelongsTo(Type = typeof(Department), Column = "Id")] public Department Department { get; set; } } }
When I run the code
ActiveRecordStarter.Initialize(ActiveRecordSectionHandler.Instance, typeof(Company), typeof(Department), typeof(Employee)); IList employees = Employee.FindAllByProperty("FirstName", firstName);
I get an error:
NHibernate.HibernateException : Could not find named connection string Server=(local);initial catalog=DemoDB;Integrated Security=SSPI
What's wrong with the connection?