-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problems configuring NHibernate in app.config.
PostPosted: Mon Apr 14, 2008 1:32 pm 
Newbie

Joined: Thu Jul 26, 2007 6:58 am
Posts: 19
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 2:30 pm 
Newbie

Joined: Thu Jul 26, 2007 6:58 am
Posts: 19
I commented

objConfiguration.Configure();

and it didn't fail anymore.

Just in case anyone will need that.

Cheers


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.