Hi there,
Can I please request someone to help me with Nhibernate problem. I am newbie but I have read lots of stuff related to my error and unfortunately I dont get any solution which is working. When I try to run the Quickstart sample - I am having Visual Studio 2005 + Nhibernate 1.2.0 and SQL Server 2000.
I am getting an error as mentioned below.
Detail Error Message
Could not compile the mapping document: NHibernate.Examples.QuickStart.User.hbm.
xml
NHibernate.HibernateException: The dialect was not set. Set the property hiberna
te.dialect.
at NHibernate.Dialect.Dialect.GetDialect()
at NHibernate.Dialect.Dialect.GetDialect(IDictionary props)
at NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc, String
name)
My .NET CLASS (Same as mentioned in QuickStart Guide - File is saved as Class1.cs)
using System;
using System.Collections.Generic;
using System.Text;
namespace NHibernate.Examples.QuickStart
{
public class User
{
private string id;
private string userName;
private string password;
private string emailAddress;
private DateTime lastLogon;
public User()
{
}
public virtual string Id
{
get { return id; }
set { id = value; }
}
public virtual string UserName
{
get { return userName; }
set { userName = value; }
}
public virtual string Password
{
get { return password; }
set { password = value; }
}
public virtual string EmailAddress
{
get { return emailAddress; }
set { emailAddress = value; }
}
public virtual DateTime LastLogon
{
get { return lastLogon; }
set { lastLogon = value; }
}
}
}
SQL TABLE (Same as mentioned in QuickStart Guide)
use Auction (as Auction is my DATABASE NAME)
go
CREATE TABLE users (
LogonID nvarchar(20) NOT NULL default '0',
Name nvarchar(40) default NULL,
Password nvarchar(20) default NULL,
EmailAddress nvarchar(40) default NULL,
LastLogon datetime default NULL,
PRIMARY KEY (LogonID)
)
go
NHibernate mapping file - user.hbm.xml (Build Action property is Embedded Resource)
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernate.Examples.QuickStart.User, NHibernate.Examples" table="[Auction].[dbo].[Users]">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</id>
<property name="UserName" column="Name" type="String" length="40"/>
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>
Application Configuration File (App.Config is a name)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"
/>
</configSections>
<!-- Add this element -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">
<session-factory xmlns="urn:nhibernate-configuration-2.0">
<property xmlns="urn:nhibernate-configuration-2.0"
name="hibernate.dialect"> NHibernate.Dialect.MsSql2000Dialect</property>
<property xmlns="urn:nhibernate-configuration-2.0"
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property xmlns="urn:nhibernate-configuration-2.0"
name="connection.connection_string">
Server=ALEPPO;initial
catalog=Auction;User ID=sa;Password=password;Integrated Security=True
</property>
<mapping xmlns="urn:nhibernate-configuration-2.0"
assembly="NHibernate.Examples" />
</session-factory>
</hibernate-configuration>
</configuration>
I have added Console Application Project in the same Solution. The Assembly name is ConsoleApplication1.
using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Examples.QuickStart;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate.Examples.QuickStart");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
User newUser = new User();
newUser.Id = "joe_cool";
newUser.UserName = "Joseph Cool";
newUser.Password = "abc123";
newUser.EmailAddress = "
[email protected]";
newUser.LastLogon = DateTime.Now;
// Tell NHibernate that this object should be saved
session.Save(newUser);
// commit all of the changes to the DB and close the ISession
transaction.Commit();
session.Close();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.InnerException);
Console.ReadLine();
}
}
}
}
Please Please help me ASAP. Thanks in advance.
REgards,
Nirav[/b]