I am trying to connect using Fluent NHibernate to our AS/400 iSeries DB2 server. I have the following code:

private static ISessionFactory CreateSessionFactory()
{
    return Fluently.Configure()
        .Database(DB2Configuration.Standard.ConnectionString("DataSource=MyServer;UserID=MyUser;Password=password;"))
        .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
        .BuildSessionFactory();
}

I am running nhprof, and I get the error: Could not load file or assembly 'IBM.Data.DB2' or one of its dependencies. The system cannot find the file specified.Could not load type IBM.Data.DB2.DB2Command, IBM.Data.DB2.

I know that IBM.Data.DB2.dll is the incorrect .dll for the iSeries. It should be loading IBM.Data.DB2.iSeries.dll, which is in my bin folder.

NHibernate has a way to load the iSeries dll. How can I tell Fluent to load it?

有帮助吗?

解决方案

I figured it out, just in case anybody else is struggling with this.

I took out the nhibernate.cfg.xml file and did it in code. This code appears to work:

private static ISessionFactory CreateSessionFactory()
{
    ISessionFactory factory = null;

    var cfg = new Configuration();
    cfg.DataBaseIntegration(x =>
    {
        x.ConnectionString = "DataSource=MyServer;UserID=MyUser;Password=password; DataCompression=True;";
        x.Dialect<DB2400Dialect>();
        x.Driver<DB2400Driver>();
    });

    factory = Fluently.Configure(cfg)
        .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
        .BuildSessionFactory();

    return factory;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top