David,

I copied your code into my test application, unfortunately I get the
same problem. I also have a reference to the Oracle.DataAccess.dll
(copy local was set to false, but I tried true to no avail).

The full error stack is:

FluentNHibernate.Cfg.FluentConfigurationException was unhandled
  Message="An invalid or incomplete configuration was used while
creating a SessionFactory. Check PotentialReasons collection, and
InnerException for more detail.\r\n\r\n"
  Source="FluentNHibernate"
  StackTrace:
       at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory
() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg
\FluentConfiguration.cs:line 98
       at ConsoleApplication2.Program.CreateSessionFactory() in C:
\Documents and Settings\Chris.Young\My Documents\Visual Studio
2008\Projects\ConsoleApplication2\ConsoleApplication2\Program.cs:line
141
       at ConsoleApplication2.Program.Main() in C:\Documents and
Settings\Chris.Young\My Documents\Visual Studio 2008\Projects
\ConsoleApplication2\ConsoleApplication2\Program.cs:line 22
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String
[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
       at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
       at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.InvalidCastException
       Message="Unable to cast object of type
'Oracle.DataAccess.Client.OracleConnection' to type
'System.Data.Common.DbConnection'."
       Source="NHibernate"
       StackTrace:
            at
NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare
()
            at
NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect
dialect, IConnectionHelper connectionHelper)
            at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update
(ISessionFactory sessionFactory)
            at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration
cfg, IMapping mapping, Settings settings, EventListeners listeners)
            at NHibernate.Cfg.Configuration.BuildSessionFactory()
            at
FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:
\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line
93
       InnerException:



The entire program I am using is:

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OracleClient;
using ConsoleApplication2.Entities;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main()
        {
           var sessionFactory = CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    // create a couple of Stores each with some
Products and Employees
                    var barginBasin = new Store { Name = "Bargin
Basin" };
                    var superMart = new Store { Name = "SuperMart" };

                    var potatoes = new Product { Name = "Potatoes",
Price = 3.60 };
                    var fish = new Product { Name = "Fish", Price =
4.49 };
                    var milk = new Product { Name = "Milk", Price =
0.79 };
                    var bread = new Product { Name = "Bread", Price =
1.29 };
                    var cheese = new Product { Name = "Cheese", Price
= 2.10 };
                    var waffles = new Product { Name = "Waffles",
Price = 2.41 };

                    var daisy = new Employee { FirstName = "Daisy",
LastName = "Harrison" };
                    var jack = new Employee { FirstName = "Jack",
LastName = "Torrance" };
                    var sue = new Employee { FirstName = "Sue",
LastName = "Walkters" };
                    var bill = new Employee { FirstName = "Bill",
LastName = "Taft" };
                    var joan = new Employee { FirstName = "Joan",
LastName = "Pope" };

                    // add products to the stores, there's some
crossover in the products in each
                    // store, because the store-product relationship
is many-to-many
                    AddProductsToStore(barginBasin, potatoes, fish,
milk, bread, cheese);
                    AddProductsToStore(superMart, bread, cheese,
waffles);

                    // add employees to the stores, this relationship
is a one-to-many, so one
                    // employee can only work at one store at a time
                    AddEmployeesToStore(barginBasin, daisy, jack,
sue);
                    AddEmployeesToStore(superMart, bill, joan);

                    // save both stores, this saves everything else
via cascading
                    session.SaveOrUpdate(barginBasin);
                    session.SaveOrUpdate(superMart);

                    transaction.Commit();
                }

                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    var stores = session.CreateCriteria(typeof(Store))
                      .List<Store>();

                    foreach (var store in stores)
                    {
                        WriteStorePretty(store);
                    }
                }

                Console.ReadKey();
            }
        }

        public static void AddEmployeesToStore(Store store, params
Employee[] employees)
        {
            foreach (var employee in employees)
            {
                store.AddEmployee(employee);
            }
        }
        private static ISessionFactory CreateSessionFactory()
        {

         var idk =    Fluently
                    .Configure()
                    .Database(OracleDataClientConfiguration
                                  .Oracle10
                                  .UseReflectionOptimizer()
                                  .MaxFetchDepth(3)
                                  .AdoNetBatchSize(500)
                                  //.DefaultSchema("production")
                                  //.Cache(c => c.UseQueryCache()
                                  //      .ProviderClass<SysCacheProvider>
()
                                  //)
                                  .ConnectionString(cs => cs
                                        .Server("hostname")
                                        .Port(1521)
                                        .Instance("dbname")
                                        .Username("username")
                                        .Password("password")
                                        .Pooling(true)
                                        .StatementCacheSize(100)
                                        .OtherOptions("Min Pool
Size=10;Incr Pool Size=5;Decr Pool Size=2;")
                                        )
                    // It does this automatically.. but I like to be
explicit ;)
                                .ProxyFactoryFactory
("NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle")
                    // Testing/NHProf stuff
                    //.Raw("generate_statistics", "true")
                    //.ShowSql()
                    )
                    .Mappings(mappings => mappings
                        .FluentMappings.AddFromAssemblyOf<Program>
());

            return idk.BuildSessionFactory();
        }

        private static void BuildSchema(Configuration config)
        {
            // this NHibernate tool takes a configuration (with
mapping info in)
            // and exports a database schema from it
            new SchemaExport(config)
                .Create(false, true);
        }

        private static void WriteStorePretty(Store store)
        {
            Console.WriteLine(store.Name);
            Console.WriteLine(" Products:");

            foreach (var product in store.Products)
            {
                Console.WriteLine(" " + product.Name);
            }

            Console.WriteLine(" Staff:");

            foreach (var employee in store.Staff)
            {
                Console.WriteLine(" " + employee.FirstName + " " +
employee.LastName);
            }

            Console.WriteLine();
        }

        public static void AddProductsToStore(Store store, params
Product[] products)
        {
            foreach (var product in products)
            {
                store.AddProduct(product);
            }
        }
    }
}

The entities and maping files are the ones from the Getting started
application at 
http://github.com/jagregory/fluent-nhibernate/tree/master/src/Examples.FirstProject

The exception is generated when BuildSessionFactory() is called. From
the stack trace, it looks as though the problem is in NHibernate
itself, not Fluent. Which leads to the issue of NHibernate being at
version 3.x, while the one included with Fluent is 2.x


Chris.



On Sep 2, 12:35 pm, "David R. Longnecker" <tiredstud...@gmail.com>
wrote:
> AFAIK, there weren't any changes between RC and RTM, but the latest
> bits are always good to have.
>
> Here's what I'm using for one of our production systems.  I'm using
> the builder...
>
> Fluently
>                     .Configure()
>                     .Database(OracleDataClientConfiguration
>                                   .Oracle10
>                                   .UseReflectionOptimizer()
>                                   .MaxFetchDepth(3)
>                                   .AdoNetBatchSize(500)
>                                   .DefaultSchema("production")
>                                   .Cache(c => c
>                                                   .UseQueryCache()
>
> .ProviderClass<SysCacheProvider>()
>                                   )
>                                   .ConnectionString(cs => cs
>
> .Server("database_server")
>
> .Instance("instance.domain.net")
>
> .Username("username")
>
> .Password("password")
>                                                               .Pooling(true)
>
> .StatementCacheSize(100)
>
> .OtherOptions("Min Pool Size=10;Incr Pool Size=5;Decr Pool Size=2;")
>                                   )
>
>                     // It does this automatically.. but I like to be explicit 
> ;)
>
> .ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory,
> NHibernate.ByteCode.Castle")
>                     // Testing/NHProf stuff
>                     //.Raw("generate_statistics", "true")
>                     //.ShowSql()
>                     )
>                     .Mappings(mappings => mappings
>
> .FluentMappings.AddFromAssemblyOf<StudentMap>());
>
> So, I ripped all of that out and tried using the connection string.
> Thankfully, some PowerShell-fu from earlier today had a TNS-esque
> connection string on my desktop.
>
> Fluently
>                     .Configure()
>                     .Database(OracleDataClientConfiguration
>                                   .Oracle10
>                                   .ConnectionString(c => c.Is( "Data
> Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=instance)));User
> Id=user;Password=password;"))
>                     // It does this automatically.. but I like to be explicit 
> ;)
>
> .ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory,
> NHibernate.ByteCode.Castle")
>                     //.Raw("generate_statistics", "true")
>                     //.ShowSql()
>                     )
>                     .Mappings(mappings => mappings
>
> .FluentMappings.AddFromAssemblyOf<StudentMap>());
>
> Clicked to rerun the tests and everything green.  I reread through all
> of the implementations of OracleDataClient and I can't see where it
> might be going astray.  There shouldn't be a difference between that
> TNS-body connection string and a standard TNS reference.  Like I said,
> your conn string looks right.
>
> Now, I'm assuming you have Oracle.DataAccess.dll referenced AND 'Copy
> Local' set to True?
>
> The next step would be if there's something in your conventions
> (though I don't see any specified) that is breaking a constraint you
> have in your Oracle environment.  If you could post up the full error,
> that'd greatly help.  Hopefully it references the line number in FNH
> that is hanging up for you.
>
> --
> David R. Longnecker
> blog:http://blog.tiredstudent.com
> twitter: dlongnecker
>
> "Good design is a Renaissance attitude that combines technology,
> cognitive science, human need, and beauty to produce something." -
> Paola Antonelli
>
> On Tue, Sep 1, 2009 at 8:43 PM, Chris<chris.yo...@alsenviro.com> wrote:
>
> > David,
>
> > Thanks for your reply.
>
> > I have tried using a connection string which in effect bypasses the
> > TNS config files, but I get the same error. I do not believe there is
> > a problem actually connecting to the database itself: that seems to
> > work ok as I can see the session connected at the database.
>
> > The error message I posted was the one from the Inner exception. The
> > top level error message was a generic, cover everything sort of thing:
> >      "An invalid or incomplete configuration was used while creating
> > a SessionFactory. Check PotentialReasons collection, and
> > InnerException for more detail"
>
> > I'm running 1.0RC. I will download the RTM version and see how I go
> > with it.
>
> > I had a look at the link you supplied, but I must admit I'm on a
> > pretty steep learning curve with this, so at the moment, I'm not up to
> > speed on all the configuration and setup for NHibernate.
>
> > Chris.
>
> > On Sep 2, 12:06 am, "David R. Longnecker" <tiredstud...@gmail.com>
> > wrote:
> >> Chris-
>
> >> That connection string should work. I've honestly never tried
> >> OracleClient with FNH--preferring, like you, the Oracle ODP.  I'm
> >> assuming your using a tnsnames.ora reference since you're not using
> >> the ConnectionStringBuilder built into OracleDataClientConfiguration.
>
> >> A few questions:
>
> >> - Have you tried building a TNS-less connection string using the
> >> ConnectionStringBuilder?  Same thing?
>
> >> - Did the exception you receive return any further details in the
> >> inner exception?
>
> >> - Are you running 1.0 RTM?
>
> >> I also came across this from Fabio.  I haven't ran into the specified
> >> situation, but perhaps our Oracle environment is setup with different
> >> parameters (I'm happily NOT the Oracle DBA. :))
>
> >>http://groups.google.com/group/nhusers/browse_thread/thread/8acd81dab...
>
> >> -dl
>
> >> --
> >> David R. Longnecker
> >> blog:http://blog.tiredstudent.com
> >> twitter: dlongnecker
>
> >> "Good design is a Renaissance attitude that combines technology,
> >> cognitive science, human need, and beauty to produce something." -
> >> Paola Antonelli
>
> >> On Tue, Sep 1, 2009 at 12:12 AM, Chris<chris.yo...@alsenviro.com> wrote:
>
> >> > I am trying to evaluate Fluent NHibernate for a new development
> >> > project. I am attempting to use the 'Getting Started' project from the
> >> > Fluent NHibernate Wiki, adapted for use with an Oracle database. I
> >> > want to be able to use the Oracle Data Provider rather than the
> >> > Microsoft version because of extra features in the Oracle version and
> >> > the termination of support for the Microsoft offering. I can connect
> >> > to the database but I get the following error after the
> >> > Fluently.Configure() ....  function throws an exception:
>
> >> > Unable to cast object of type
> >> > 'Oracle.DataAccess.Client.OracleConnection' to type
> >> > 'System.Data.Common.DbConnection'
>
> >> > The code I am using is just the getting started code modified for use
> >> > with Oracle.:
>
> >> > private static ISessionFactory CreateSessionFactory()
> >> >        {
> >> >            //return Fluently.Configure()
> >> >            //    .Database(SQLiteConfiguration.Standard
> >> >            //        .UsingFile(DbFile))
> >> >            //    .Mappings(m =>
> >> >            //        m.FluentMappings.AddFromAssemblyOf<Program>())
> >> >            //    .ExposeConfiguration(BuildSchema)
> >> >            //    .BuildSessionFactory();
>
> >> >            var cfg = OracleDataClientConfiguration.Oracle10
> >> >                .ConnectionString( c => c
> >> >                    .Is( "DATA SOURCE=DEVDB;" +
> >> >                         "PERSIST SECURITY INFO=True;" +
> >> >                         "USER ID=TRY_FLUENT;" +
> >> >                         "PASSWORD=TEST" ) );
>
> >> >            return Fluently.Configure()
> >> >                    .Database( cfg )
> >> >                    .Mappings( m => m
> >> >                        .FluentMappings.AddFromAssemblyOf<Program>() )
> >> >                    .BuildSessionFactory();
> >> >        }
>
> >> > I know it does work with the Microsoft data access as a schema was
> >> > built and tables were populated with data when I ran the program.
>
> >> > Can anyone please help with a solution as I have no idea how to solve
> >> > this problem.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to