1

我正在为我的 ASP.NET Web 应用程序使用 NHibernate、Persistence API 和 MYSql DB;我有以下 nhibernate 映射文件:

    <?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="JPUMain" transaction-type="RESOURCE_LOCAL">
    <provider>NPersistence.NHibernate.NHibernatePersistence</provider>   
    <class>JDAL.Impl.Entities.Answer</class>   
    <properties>
      <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
      <property name="connection.connection_string">Database=DBName;Data Source=localhost;User Id=root;Password=;Charset=utf8;</property>
      <property name="dialect">NHibernate.Dialect.MySQLDialect</property>
      <property name="query.substitutions">true=1;false=0</property>
      <property name="connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
      <property name="show_sql" value="true"/>
      <property name="hbm2ddl.keywords" value="none"/>
      <property name="hbm2ddl.auto" value="validate"/>
    </properties>
  </persistence-unit>
</persistence>

现在我正在使用 ASP.NET 登录控件进行登录。当我在登录页面上提供无效凭据时,预期的行为是它不应该重定向到任何其他页面,并且在处理服务器端的代码后它应该在登录页面本身上显示一条错误消息。我已经调试了我的代码,并且服务器端处理似乎很好,但是在执行验证登录凭据是否正确的服务器端方法后,它的网站挂起。在超时时间之后,它会显示以下错误消息:

 A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

SQLExpress database file auto-creation error:

The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:

    If the application is running on either Windows 7 or Windows Server 2008R2, special configuration steps are necessary to enable automatic creation of the provider database. Additional information is available at: http://go.microsoft.com/fwlink/?LinkId=160102. If the application's App_Data directory does not already exist, the web server account must have read and write access to the application's directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
    If the application's App_Data directory already exists, the web server account only requires read and write access to the application's App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the application's App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server account's credentials are used when creating the new database.
    Sql Server Express must be installed on the machine.
    The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.

我的第一个问题是,为什么它试图连接到 SQL Server?我没有在我的应用程序的任何地方使用 SQL Server!

我的第二个问题是,当我提供有效凭据时它工作正常,因为它会验证它们并成功重定向到下一页。此外,如果我提供无效凭据,它会处理服务器端方法以正确验证凭据,但之后它会挂起。

任何人都可以对此有所了解吗?

4

1 回答 1

1

该错误来自 Login 控件,默认情况下,该控件在您的 App_Data 目录中需要一个 MDF 数据库。

您需要更改您的成员资格提供程序以指向您的 MySQL 实例。

于 2013-01-03T13:25:48.730 回答