Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# NHibernate或FluentNHibernate不';似乎无法处理NpgsqlException_C#_Sql Server_Postgresql_Nhibernate_Fluent Nhibernate - Fatal编程技术网

C# NHibernate或FluentNHibernate不';似乎无法处理NpgsqlException

C# NHibernate或FluentNHibernate不';似乎无法处理NpgsqlException,c#,sql-server,postgresql,nhibernate,fluent-nhibernate,C#,Sql Server,Postgresql,Nhibernate,Fluent Nhibernate,我尝试使用NHibernate和Fluent连接PostgreSQL和SQL Server数据库。我试图连接到一个不存在的数据库来处理这个用户的可能性。当我运行测试时,当我使用PostgreSQL时,我收到一条消息,如“NpgsqlException未通过用户代码处理”。当我尝试使用SQL Server时,SqlException被正确处理。以下是我的PostgreSQL应用程序中的连接代码 try{ this.sess

我尝试使用NHibernate和Fluent连接PostgreSQL和SQL Server数据库。我试图连接到一个不存在的数据库来处理这个用户的可能性。当我运行测试时,当我使用PostgreSQL时,我收到一条消息,如“NpgsqlException未通过用户代码处理”。当我尝试使用SQL Server时,SqlException被正确处理。以下是我的PostgreSQL应用程序中的连接代码

              try{
                        this.sessionFactory = Fluently.Configure()
                        .Database(
                            PostgreSQLConfiguration.PostgreSQL82.ConnectionString(
                                    @"Server=" + this.iGreffeDesktop.Hostname +
                                    ";Port=" + this.iGreffeDesktop.Port +
                                    ";Database=" + this.iGreffeDesktop.Database +
                                    ";User ID=" + this.iGreffeDesktop.Username +
                                    ";Password=" + this.iGreffeDesktop.Password +
                                    ";")
                        .Mappings(
                            m => m.FluentMappings
                                .AddFromAssemblyOf<Comptes>())
                        .BuildSessionFactory();
             }
             catch (Exception e)
             {
                  this.error = "Connection error!!!";
             }
试试看{
this.sessionFactory=fluntly.Configure()
.数据库(
PostgreSQLConfiguration.PostgreSQL82.ConnectionString(
@“Server=“+this.iGreffeDesktop.Hostname”+
“Port=“+this.iGreffeDesktop.Port+
“Database=“+this.iGreffeDesktop.Database”+
“用户ID=“+this.iGreffeDesktop.Username”+
“Password=“+this.iGreffeDesktop.Password”+
";")
.映射(
m=>m.FluentMappings
.AddFromAssemblyOf())
.BuildSessionFactory();
}
捕获(例外e)
{
this.error=“连接错误!!!”;
}
SQL Server的和

             try{
                   this.sessionFactory = Fluently.Configure()
                        .Database(
                        MsSqlConfiguration.MsSql2005
                                .ConnectionString(
                                    @"Server=" + this.iGreffeDesktop.Hostname +
                                    ";initial catalog=" + this.iGreffeDesktop.Database +
                                    ";user=" + this.iGreffeDesktop.Username +
                                    ";password=" + this.iGreffeDesktop.Password +
                                    ";")
                                .ShowSql()

                        .Mappings(
                            m =>
                                m.FluentMappings
                                    .AddFromAssemblyOf<Comptes>()
                        )
                        .BuildSessionFactory();
             }
             catch (Exception e)
             {
                  this.error = "Connection error!!!";
             }
试试看{
this.sessionFactory=fluntly.Configure()
.数据库(
MsSqlConfiguration.MsSql2005
.连接字符串(
@“Server=“+this.iGreffeDesktop.Hostname”+
“初始目录=“+this.iGreffeDesktop.Database”+
“user=“+this.iGreffeDesktop.Username+
“password=“+this.iGreffeDesktop.password”+
";")
.ShowSql()
.映射(
m=>
m、 FluentMappings
.AddFromAssemblyOf()的
)
.BuildSessionFactory();
}
捕获(例外e)
{
this.error=“连接错误!!!”;
}
我在NET3.5上使用NHibernate2.1.2.4构建。我试图处理NpgsqlException,但错误消息仍然出现。我的代码中缺少什么东西,还是NHibernate错误

编辑:这似乎是一个偶然的问题。基本上,我使用在AutoCAD环境中运行的Visual Studio C#编写了一个连接表单。用户在表单中输入连接信息,我的脚本尝试连接到数据库。上面代码的目的是尝试连接到数据库,如果没有,则返回向用户发送错误消息

我尝试了上面的代码,将“Comptes”类替换为“ComptesMap”类谁是NHibernate Comptes mapping类以查看发生了什么。我发现第一次在AutoCAD中运行脚本时,脚本连接到任何数据库,即使是不存在的数据库!!!在关闭AutoCAD并重新打开它之后,我再次运行脚本,然后在任何PostgreSQL数据库上,即使是主义者


我真的很麻烦。这表明存在环境问题。我是使用NHibernate的新手。我尝试连接在Web上找到的代码。我不明白我的代码出了什么问题。

我在脚本中发现了一个对象的持久性问题,它超出了这个问题的范围,这解释了为什么我第一次成功连接n、 其他的也成功了

但我在本文中发现了如何处理Fluent NHibernate的异常:

我只是通过以下方式更改代码:

 try {
      ... creation of the sessionFactory for both database types
 }
 catch (FluentNHibernate.Cfg.FluentConfigurationException e)
 {
      this.error = e.InnerException.Message;
 }
现在,它向用户显示连接是否失败