-->
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.  [ 3 posts ] 
Author Message
 Post subject: Changing connection string
PostPosted: Fri Jan 11, 2008 2:03 pm 
Beginner
Beginner

Joined: Sun Nov 18, 2007 10:39 am
Posts: 46
Location: Liverpool, England
Hi,
What do I need to do to change the connection string NHibernate is using mid application? I've got the following in my helper class:

Code:
Public Class NHibernateHelper

  Private Shared sessionFactory As ISessionFactory
 
  Public Shared Sub ChangeConnection(ByVal ConnectionString As String)
    Dim dct As New Dictionary(Of String, String)
    dct.Add("hibernate.dialect", "NHibernate.Dialect.MsSql2000Dialect")
    dct.Add("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider")
    dct.Add("hibernate.connection.connection_string", ConnectionString)
    Dim cfg As New Configuration
    cfg.Configure().SetProperties(dct)
    sessionFactory = cfg.Configure().BuildSessionFactory
End Sub

[...]


This looks promising, but when I try to build the session factory for the second time I get an error that I'm trying to add a duplicate mapping. Do I need to clear my existing mappings somehow before opening the new factory? If so, how?

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 12:34 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
You're calling Configure() twice.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 15, 2008 9:12 am 
Beginner
Beginner

Joined: Sun Nov 18, 2007 10:39 am
Posts: 46
Location: Liverpool, England
marcal wrote:
You're calling Configure() twice.


D'oh, so I am. Changed it as follows and it works fine now

Code:
sessionFactory = cfg.Configure().SetProperties(dct).BuildSessionFactory


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