Hi,
I had hibernate.cfg.xml working with NHibernate 1.2.1, but now I need to put the configurations into app.config, what I did was:
to add
Code:
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
into <ConfigSections>
and the configuration itself (inside app.config):
Code:
<nhibernate>
<add key="hibernate.show_sql" value="true"/>
<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect"/>
<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
<add key="hibernate.connection.connection_string" value=""/>
</nhibernate>
The application seems to be still looking for the hibernate.cfg.xml, because I get the following exception:
Code:
problem parsing configuration : System.IO.FileNotFoundException: Could not find file 'E:\Projects\Test\bin\Debug\hibernate.cfg.xml'.
File name: 'E:\Projects\Test\bin\Debug\hibernate.cfg.xml'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlValidatingReaderImpl.Read()
at System.Xml.XmlValidatingReader.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at NHibernate.Cfg.Configuration.Configure(XmlTextReader reader)
The way I initialise NHibernate:
Code:
Configuration objConfiguration = new Configuration();
objConfiguration.Configure();
NHibernate.Mapping.Attributes.HbmSerializer.Default.Validate = true; // Enable validation (optional)
// Here, we serialize all decorated classes (but you can also do it class by class)
objConfiguration.AddInputStream( NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize(
System.Reflection.Assembly.GetExecutingAssembly()
));
// Now you can use this configuration to build your SessionFactory..
_objFactory = objConfiguration.BuildSessionFactory();
_bNHibernateInitialized = true;
Can anyone help please.
Regards, Jean