建立与SQL Server的连接时发生与网络相关或特定于实例的错误

时间:2013-01-03 13:10:12

标签: c# asp.net sql-server nhibernate

我在我的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!

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

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

1 个答案:

答案 0 :(得分:1)

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

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

相关问题