Solved

NHibernate: "cannot open connection"

Posted on 2010-09-01
5
1,048 Views
Last Modified: 2012-05-10
On the line of code below which says FAILS HERE I get an exception.

"cannot open connection"

I assume I have a configuration problem with the hibernate.cfg.xml file but can not find the problem since the exception is being thrown by NHibernate. Any idea where to look?



  at NHibernate.Impl.SessionFactoryImpl.OpenConnection()
   at NHibernate.Impl.ConnectionManager.Connect()
   at NHibernate.Impl.ConnectionManager.GetConnection()
   at NHibernate.Impl.BatcherImpl.Prepare(IDbCommand cmd)
   at NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd)
   at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, RowSelection selection, ISessionImplementor session)
   at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
   at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
   at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
   at NHibernate.Hql.Classic.QueryTranslator.List(ISessionImplementor session, QueryParameters queryParameters)
   at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results)
   at NHibernate.Impl.SessionImpl.Find[T](String query, QueryParameters parameters)
   at NHibernate.Impl.QueryImpl.List[T]()
   at PizzaPilot.Server.Runtime.Impl.ServerObjectStoreImpl.GetAllDeviceRecords() in C:\Documents and Settings\Administrator\Desktop\Code\PPServer\releases\DDServer_AmericanaPhase1\PizzaPilotRuntime\PizzaPilot\Server\Runtime\Impl\ServerObjectStoreImpl.cs:line 328
   at MobileService.InitializeComponent() in c:\Documents and Settings\Administrator\Desktop\Code\PPServer\releases\DDServer_AmericanaPhase1\CentralizedMobileService\App_Code\MobileService.cs:line 43
public IList<DeviceIDRecord> GetAllDeviceRecords()

        {

            ISessionFactory factory = nhibConfig.BuildSessionFactory();

            ISession session = factory.OpenSession();



            String q = "from DeviceIDRecord as rec where rec.UID is not null";

            IQuery query = session.CreateQuery(q);

            IList<DeviceIDRecord> evtList = query.List<DeviceIDRecord>();  <<<<<< FAILS HERE



            return evtList;

        }

Open in new window

0
Comment
Question by:newbieweb
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
tikusbalap earned 500 total points
Comment Utility
Maybe it was something wrong in your hql or .hbm config.

Try change to simple query to test:

IQuery query = session.CreateQuery("from DeviceIDRecord");
IList<DeviceIDRecord> evtList = query.List<DeviceIDRecord>();

Is there any result?
0
 

Author Comment

by:newbieweb
Comment Utility
No, same error.  It's a connection problem.

0
 
LVL 6

Expert Comment

by:tikusbalap
Comment Utility
What database are you using? And let me see your connection string as well.
0
 

Author Comment

by:newbieweb
Comment Utility
I am using SQL Express 2005.

    <property name="connection.connection_string">Server=localhost\SQLEXPRESS;initial catalog=PPDB01;User Id=sa;Password=sqlserversapassword;</property>


Is there a way to verify this connection string is actually being use by NHibernate?
0
 

Author Closing Comment

by:newbieweb
Comment Utility
Thanks.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now