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