-->
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.  [ 6 posts ] 
Author Message
 Post subject: where should i put the hibernate.cfg.xml in asp.net
PostPosted: Fri Jul 01, 2005 12:36 am 
my web appliction port:
problem parsing configuration : System.IO.FileNotFoundException: can not find:


Top
  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 7:47 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
i'm not using an external file with my ASP.NET app. rather the hibernate config stuff is contained within the web.config file:

Code:
<?xml version="1.0" ?>
<configuration>
   <configSections>
      <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
   </configSections>
   <nhibernate>
      <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="Server=ABUNDANCE;initial catalog=VirtualFamilyOffice_v3;UID=sa;PWD=2good4u" />
      <add key="hibernate.cache.provider_class" value="NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache" />
   </nhibernate>
   <log4net>
      <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
         <param name="File" value="C:\\VFOLogs\\log.txt" />
         <param name="AppendToFile" value="true" />
         <param name="RollingStyle" value="Date" />
         <param name="DatePattern" value="yyyy.MM.dd" />
         <param name="StaticLogFileName" value="true" />
         <layout type="log4net.Layout.PatternLayout,log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
         </layout>
      </appender>

      <root>
         <level value="DEBUG" />
         <appender-ref ref="RollingFileAppender" />
      </root>
   </log4net>
   </system.web>
</configuration>


hth,

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2005 3:04 am 
i use web.config too.
but i don't know how to config "mapping assemble" in Web.config.

there is only assemble config in my hibernate.cgf.xml:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0" >
<session-factory name="NHibernate.Test">
<!-- mapping files -->
<mapping assembly="Cdma.Example.Hibernate" />
</session-factory>
</hibernate-configuration>

i config the other properties in Web.config,
but because my project is contain a few assemble, i don't want go write like

cfg.AddAssembly("assemble1");
cfg.AddAssembly("assemble2");

in my code.

so i need hibernate.cfg.xml.


Top
  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 3:47 am 
Newbie

Joined: Thu Jun 02, 2005 6:00 am
Posts: 12
Location: Ostrava, Czech Republic
I am using web.config as well.
As for the building ConfigFactory, try using this:
Code:
config = new Configuration();

            
ArrayList list = new ArrayList();
Assembly[] assArr = AppDomain.CurrentDomain.GetAssemblies();

for(int i = 0; i < assArr.Length; i++)
{
   if(assArr[i].GetName().ToString().IndexOf("Lib") > 0)
   {
      config.AddAssembly(assArr[i]);
   }
}


point is, that I separate logic and view (I am using maverick.Net - MVC) and all assembles containing Business objects and their DAO are called {something}Lib. Using this simple convention, I can simply map all BO without any additional config file.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 5:41 pm 
Beginner
Beginner

Joined: Wed Jun 29, 2005 10:40 am
Posts: 30
Location: denver, co
I made a Configurator class that calls Configure with the path to the hibernate.cfg.xml file. I had it search the bin and application directories.

Do something like this:
Code:
string appPath = HttpContext.Current.Request.ApplicationPath;
string rootedAppPath = HttpContext.Current.Server.MapPath(appPath);
string cfgPath = Path.Combine(rootedAppPath, "hibernate.cfg.xml");
Configuration conf = new Configuration();
conf.Configure(cfgPath);


I do this once when the application starts up in an http module.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 9:36 pm 
Newbie

Joined: Sat Dec 10, 2005 9:31 pm
Posts: 3
I tried in asp.net 2.0, nhibernate just look at "~/bin" directory first for hibernate.cfg.xml, you can put it there and it runs ok.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.