简体   繁体   English

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

[英]A network-related or instance-specific error occurred while establishing a connection to SQL Server

I am using NHibernate, Persistence API annd MYSql DB for my ASP.NET web application; 我正在为我的ASP.NET Web应用程序使用NHibernate,Persistence API和MYSql DB。 and I have the following nhibernate mapping file: 并且我有以下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>

Now I am using ASP.NET login control to login. 现在,我正在使用ASP.NET登录控件进行登录。 When I provide invalid credentials on the login page, then the expected behavior is that it should not redirect to any other page, and it should show a error message on the login page itself after processing the code on the server side. 当我在登录页面上提供无效的凭据时,则预期的行为是它不应重定向到任何其他页面,并且在服务器端处理了代码后应在登录页面本身上显示错误消息。 I have debug my code, and the server side processing seems to fine, but it website hangs after executing the server side method which verifies that whether login credentials are proper or not. 我已经调试了我的代码,服务器端处理似乎正常,但是执行服务器端方法后该网站挂起,该方法验证登录凭据是否正确。 And after a timeout period, it displays following error message: 超时后,它会显示以下错误消息:

 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.

My first question is, why it is trying to connect to SQL Server? 我的第一个问题是,为什么它要尝试连接到SQL Server? I am not using SQL Server anywhere in my app! 我不在应用程序中的任何地方使用SQL Server!

And my second question is that it works fine when I provide valid credentials, as it verifies them and redirect to next page successfully. 我的第二个问题是,当我提供有效的凭据时,它可以正常工作,因为它可以验证它们并成功重定向到下一页。 Also, if I provide invalid credentials, it processes the server side method to validate the credentials properly, but after that it hangs. 另外,如果我提供了无效的凭据,它将处理服务器端方法以正确验证凭据,但此后挂起。

Can any one please put some light on this? 可以请任何一个对此进行说明吗?

The error is coming from the Login control which by default expects an MDF database in your App_Data directory. 该错误来自登录控件,默认情况下,该控件需要App_Data目录中的MDF数据库。

You will need to change your membership provider to point to your MySQL instance. 您将需要更改成员资格提供程序以指向您的MySQL实例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何超时“建立与SQL Server的连接时发生与网络有关或特定于实例的错误”错误 - How to timeout “A network-related or instance-specific error occurred while establishing a connection to SQL Server” error "出现错误:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误" - Getting error: A network-related or instance-specific error occurred while establishing a connection to SQL Server 得到错误“与SQL Server建立连接时发生与网络相关或特定于实例的错误…” - Getting error “A network-related or instance-specific error occurred while establishing a connection to SQL Server…” 在EF 6.2.0中建立与SQL Server的连接时发生与网络相关或特定于实例的错误 - A network-related or instance-specific error occurred while establishing a connection to SQL Server in EF 6.2.0 “建立与SQL Server的连接时发生了与网络相关或特定于实例的错误。” - “A network-related or instance-specific error occurred while establishing a connection to SQL Server.” 本地数据库:“与SQL Server建立连接时发生与网络相关或特定于实例的错误。” - Local DB: “A network-related or instance-specific error occurred while establishing a connection to SQL Server.” MySQL“与 SQL Server 建立连接时发生与网络相关或特定于实例的错误” - MySQL “network-related or instance-specific error occurred while establishing a connection to SQL Server” 建立与SQL Server的连接时发生与网络相关或特定于实例的错误-使用TempData时 - A network-related or instance-specific error occurred while establishing a connection to SQL Server - When using TempData 更新数据库:“建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误” - update-database: "A network-related or instance-specific error occurred while establishing a connection to SQL Server" 插入错误建立与SQL Server的连接时发生与网络相关或特定于实例的错误 - Insert ErrorA network-related or instance-specific error occurred while establishing a connection to SQL Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM