-->
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: NHibernate.ADOException "Cannot open Connection"
PostPosted: Sat Jan 10, 2009 9:20 pm 
Newbie

Joined: Thu Jul 17, 2008 12:00 am
Posts: 5
Hey Everyone..

I am new to NHibernate. I am trying to familiarize myself with it by practicing using a SQL Server Express instance running the NorthWind database.

I cannot seem to establish a connect to my database. The exception reads: "ADOException was unhandled by user code: cannot open connection"


The connection string is taken directly from the database's connection string property from within VS so I'm fairly certain it's not the issue.

Config File:


Code:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>


Helper Class (Session Factory):

Code:
public class NHibernateHelper
    {

       private static ISessionFactory _sessionFactory;

       private static ISessionFactory SessionFactory
       {

           get
           {
               if (_sessionFactory == null)
               {

                   var cfg = new Configuration();
                   cfg.Configure();
                   cfg.AddAssembly(typeof(Region).Assembly);

                   _sessionFactory = cfg.BuildSessionFactory();
               }
               return _sessionFactory;
                 
           }
       
       
       }

       public static ISession OpenSession()
       {
           return SessionFactory.OpenSession();
       }


Query (Where Exception Occurs):



Code:
public Region GetRegionByID(int id)

        {

            using (ISession session = NHibernateHelper.OpenSession())
            {

                var region = session.Get<Region>(id);

                return region;
               


            }
       
        }


The exception occurs at this line: var region = session.Get<Region>(id);

I sure hope someone can help.

Thanks a lot!

-Nick


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 10, 2009 11:16 pm 
Newbie

Joined: Thu Jul 17, 2008 12:00 am
Posts: 5
So the exception went away when I was viewing tables from within the Server explorer?! Like maybe I started the server. I dunno.


Top
 Profile  
 
 Post subject: Re: NHibernate.ADOException "Cannot open Connection"
PostPosted: Fri Aug 21, 2009 5:35 am 
Newbie

Joined: Fri Aug 21, 2009 5:31 am
Posts: 2
My source code(My documents\Projects 2008\myproject) was in a shared drive (//sasas/asas)
I changed that to c:\myproject
and it worked!


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.