Geeks With Blogs
Bob Palmer's Developer Blog .NET, SQL, and Silverlight Development

This took a lot of google foo and twiddling, so I figured I would post this.  That, and I fully expect I'll be scratching my head a few weeks from now and wondering where I put my sample XML ;)

The configuration file below assumes that you have included the bins from the following folders included with the NHibernate download (I use 2.1.1):

<Your NHibernate install frolder>\Required_For_LazyLoading\Castle\*.dll
<Your NHibernate install frolder>\Required_Bins\*.dll

And here's the App config - Adjust as needed:

 <?xml version="1.0" encoding="utf-8"?>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
      <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=MySQLComputer;Database=MyNHibernateDatabase;Trusted_Connection=True;</property>
      <property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>


Posted on Saturday, November 21, 2009 9:35 AM | Back to top

Comments on this post: NHibernate 2.1 Configuration for SQL 2005

# re: NHibernate 2.1 Configuration for SQL 2005
Requesting Gravatar...
Hi Bob!
Thanks for this post
I am using embedded SQL Server in VS 2008. and I have same conf as yours in my web.conf file, but I get the following error! It is strange since I do not have any username and password:

System.Data.SqlClient.SqlException: Cannot open database "WebMonitorUpdate" requested by the login. The login failed.
Login failed for user 'shso'

Would you please help me if you have any idea.

Thanks in advance
Left by Sheri on Dec 29, 2009 2:45 AM

# re: NHibernate 2.1 Configuration for SQL 2005
Requesting Gravatar...
Hey Sheri - haven't used the embedded version myself - I usually end up hooking directly to an external server, or a server on my local network since that better mimics deployment.

By default the configuration above assumes you're using windows authentication (i.e. is shso a login ID you know of?). Can you get to your daabase via the SQL Management tools? If so, do you use different credentials to do that?

Essentially, however you can get in there via management tools would be how you do it via the config, so I'd start with that.

FYI - a sample connection string I use when connecting to a remote host would look something like this:

<property name="connection.connection_string">Data Source=; Initial Catalog=mySQLDatabaseName; User ID=MyUserID; Password='MyPassword';</property>

Left by Bob Palmer on Dec 29, 2009 8:45 AM

# re: NHibernate 2.1 Configuration for SQL 2005
Requesting Gravatar...
I've been looking at a lot of different good sites for this info. Watch is a very common item in daily life. It can be easy for people to know the time, so good to arrange their own schedule.
Left by kasyna online on Jan 20, 2011 7:31 AM

Your comment:
 (will show your gravatar)

Copyright © BobPalmer | Powered by: