-->
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: Need Help to configure Session Factory in app.config
PostPosted: Fri Jun 01, 2007 4:05 am 
Newbie

Joined: Wed May 30, 2007 4:00 am
Posts: 4
Location: Dijon, Bourgogne, France
Hi everyone I'm working on a project which have to work on several databases.
To do this I think that the easier is to configure several session factories in the app.config file.
For the moment my first test version is working with this configuration :
App.config:
Code:
<?xml version="1.0" encoding="utf-8" ?>

<configuration>
   <configSections>
      <section
        name="nhibernate"
        type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"
    />
   </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="Password=PWD;Persist Security Info=True;User ID=Login;Initial Catalog=testFactory;Data Source=Server"
    />
   </nhibernate>
</configuration>


Everything works with this configuration. Now I Would like to use a session-facory configuration, I First wrote this :
Code:
<configuration>
   <configSections>
      <section
        name="hibernate"
        type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"
    />
   </configSections>
   <hibernate xmlns="urn:nhibernate-configuration-2.2">
      <session-factory>
         <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
         <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
         <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
         <property name="connection.connection_string">Password=PWD;Persist Security Info=True;User ID=LOGIN;Initial Catalog=testFactory;Data Source=SERVER</property>
         <property name="connection.isolation">ReadCommitted</property>
         <property name="show_sql">false</property>
         <property name="use_reflection_optimizer">false</property>
         <property name="bytecode.provider">lcg</property>
         <mapping assembly="testFactory.Chat, testFactory"/>

      </session-factory>
   </hibernate>
</configuration>


Guess What... It doesn't work : Dialet not set error.
Like if nhibernate is not loading configuration.
Does someone can explain to me what I did wrong or show me a correct app.config?
Thanks in Advance
P.S: Using Nhibernate 1.2.0

For info here is my Form1.cs code :
Code:
Configuration cfg;
            ISessionFactory factory;
            cfg = new Configuration();
            //cfg.AddFile("Chat.hbm.xml");
           
            cfg.AddAssembly("testFactory");
         
            factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession();
            ITransaction transaction = session.BeginTransaction();

            Chat c1=new Chat();
            c1.Nom="Minou";

            session.Save(c1);
            transaction.Commit();

_________________
Ouch! Not on the Head!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 5:35 am 
Newbie

Joined: Wed May 30, 2007 4:00 am
Posts: 4
Location: Dijon, Bourgogne, France
IN fact the problem cames from my Form1.cs.
For info here is the good configuration :
app.config:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <!-- Add this element -->
   <configSections>
      <section
      name="hibernate-configuration"
      type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"
/>
   </configSections>
   <!-- Add this element -->
   <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
      <session-factory>
         <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
         <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
         <property name="connection.connection_string">Password=computer;Persist Security Info=True;User ID=sa;Initial Catalog=testFactory;Data Source=01-KEIRSEBILCK\SQLEXPRESS</property>
         <mapping assembly="testFactory"/>
      </session-factory>
   </hibernate-configuration>
   </configuration>

Form1.cs
Code:
ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
            ISession session=sessionFactory.OpenSession();
            ITransaction transaction = session.BeginTransaction();

            Chat c1=new Chat();
            c1.Nom="Minou";

            session.Save(c1);
            transaction.Commit();

_________________
Ouch! Not on the Head!!


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.