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: MySql: cannot open connection
PostPosted: Tue Oct 24, 2006 8:26 pm 
Newbie

Joined: Tue Oct 24, 2006 8:14 pm
Posts: 2
Hi all,

I've been browsing the forum and have googled for this problem, but I can't seem to fix it. I keep getting an 'cannot open connection' exception and the inner exception gives a 'Could not create connection from Driver' exception.

I am using .Net 2.0, created a Console application for testing purposes, the connectionstring I use works when I am not using NHibernate.

Any suggestions?


This is what I do:

- I copied the MySql.Data.dll to the bin\Debug folder
- I reference ICSharpCode.SharpZipLib and NHibernate from my project (and they also appear in the bin\Debug folder)

The class I created:

Code:
using System;

namespace NHibernatePrototype
{
    public class Gig
    {
        private int _id;
        private string _locationName;
        private string _locationUrl;
        private DateTime _date;
        private DateTime _start;
        private DateTime _end;
       
        public Gig()
        {}
       
        public Gig(int id)
        {
            _id = id;
        }
       
        public virtual int Id
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;
            }
        }

        public virtual string LocationName
        {
            get
            {
                return _locationName;
            }
            set
            {
                _locationName = value;
            }
        }

        public virtual string LocationUrl
        {
            get
            {
                return _locationUrl;
            }
            set
            {
                _locationUrl = value;
            }
        }

        public virtual DateTime Date
        {
            get
            {
                return _date;
            }
            set
            {
                _date = value;
            }
        }

        public virtual DateTime Start
        {
            get
            {
                return _start;
            }
            set
            {
                _start = value;
            }
        }

        public virtual DateTime End
        {
            get
            {
                return _end;
            }
            set
            {
                _end = value;
            }
        }
    }
}


The Gig.hbm.xml file:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="NHibernatePrototype.Gig, NHibernatePrototype" table="gigs">
    <id name="Id" column="id" type="int">
      <generator class="assigned"  />
    </id>
    <property name="LocationName" column="location-name" type="String" length="40" />
    <property name="LocationUrl" column="location-url"  type="String" length="20" />
    <property name="Date" column="date" type="DateTime" />
    <property name="Start" column="start" type="DateTime" />
    <property name="End" column="end" type="DateTime" />
  </class>
</hibernate-mapping>


The 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.MySQLDialect" />

    <add key="hibernate.connection.driver_class"
         value="NHibernate.Driver.MySqlDataDriver" />

    <add key="hibernate.connection.connection_string"
         value="server=localhost; user id=prototype; password=prototype; database=prototype; pooling=false;" />
  </nhibernate>
</configuration>


And finally the main application that has the client code:

Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using NHibernate;
using NHibernate.Cfg;

namespace NHibernatePrototype
{
    public class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Configuration cfg = new Configuration();
                cfg.AddAssembly("NHibernatePrototype");

                ISessionFactory factory = cfg.BuildSessionFactory();
                ISession session = factory.OpenSession();

                IList gigList = session.CreateCriteria(typeof(Gig)).List();

                foreach (Gig gig in gigList)
                {
                    Console.WriteLine(gig.LocationName);
                }

                session.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.InnerException.Message);
            }

            Console.ReadLine();
        }
    }
}


Any idea why I am not able to establish a connection to the database?[/code]


Top
 Profile  
 
 Post subject: Solved!
PostPosted: Thu Oct 26, 2006 2:46 pm 
Newbie

Joined: Tue Oct 24, 2006 8:14 pm
Posts: 2
Luckily I was able to solve it myself. I think it was some sort of version / caching problem of the MySqlConnector or something. I previously had an older version installed, and after removing everyting from the MySqlConnector (also from the GAC), reinstalling everything and a reboot seemed to solve the problem.


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.