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: Configuration without xml
PostPosted: Fri Nov 21, 2008 10:50 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 7:27 am
Posts: 26
Location: Germany
Hello Forum,
after succeeding in building my first Testapplication I want to use NHibernate on real projects.

Now my first problem is the config-file.
In my application there is no database.
My application must be able to create a new database and to connect to existing databases.
Therefore I tried to configure NHibernate like follows:

Code:
public static void GenerateDatabase(int dbType, string pathToDb)
        {
            //Source of this code: http://nhibernate.sourceforge.net/NHibernateEg/NHibernateEg.Tutorial1A.html#NHibernateEg.Tutorial1A-Configuration
            var cfg = new Configuration();
            switch (dbType)
            {
                case 1://Access
                    cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.JetDriver.JetDialect");
                    cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.JetDriver.JetDriver");
                    cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathToDb);
                    break;
                case 2://Access 2007
//not implemented yet
                    break;
                case 3://MSSQL
//not implemented yet, only example
                    cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2000Dialect");
                    cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.SqlClientDriver");
                    cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, "connectionString");
                    break;
            }
            cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");

            MemoryStream stream = new MemoryStream();
            //Ask NHibernate to use fields instead of Properties
            cfg.Configure();
            cfg.AddAssembly(typeof(FgBlocks).Assembly);
            new SchemaExport(cfg).Execute(false,true,false,false);
        }


If I understood the manuals correctly, NHibernate needs configuration with the first call (here it is "var cfg = new Configuration();")

I think that's the reason, why NHibernate throws an exception in the moment I try to start a new configuration.

Is my oppinion right?
If so, how could I solve this Problem?

Please help

thanks, Telefisch


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 3:24 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 7:27 am
Posts: 26
Location: Germany
Hy Guys, could this be true?
Does nobody have the Problem to start an application without a database?

please....


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.