asp.net - 错误。 SQL 网络接口(interface),错误 : 26 - Error Locating Server/Instance Specified

标签 asp.net sql-server-2008

当我尝试在默认“我的 ASP.NET 应用程序”上创建帐户时出现上述错误。我在 Windows 7 操作系统上安装了 Ms SQLServer 2008 和 Visual Studio 2010 版本的全新副本。只是为了测试与 ASP.net 的数据库连接,我尝试使用我的 ASP.NET 应用程序创建帐户,但我得到了以下错误详细信息。我是 asp.net 开发的新手。所以我不太清楚如何解决这个错误。

  • 所有 Sql 服务都在运行。
  • 已启用 MSSQLSERVER 的所有协议(protocol)。

Server Error in '/' Application. 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 数据库文件自动创建错误:

连接字符串使用应用程序的 App_Data 目录中的数据库位置指定本地 Sql Server Express 实例。提供者试图自动创建应用程序服务数据库,因为提供者确定该数据库不存在。以下配置要求是成功检查应用服务数据库是否存在并自动创建应用服务数据库所必需的:

如果应用程序在 Windows 7 或 Windows Server 2008R2 上运行,则需要执行特殊配置步骤才能自动创建提供程序数据库。如需更多信息,请访问:http://go.microsoft.com/fwlink/?LinkId=160102 .如果应用程序的 App_Data 目录尚不存在,则 Web 服务器帐户必须具有对应用程序目录的读写权限。这是必要的,因为 Web 服务器帐户将自动创建 App_Data 目录(如果该目录尚不存在)。

如果应用程序的 App_Data 目录已经存在,则 Web 服务器帐户只需要对应用程序的 App_Data 目录具有读写权限。这是必要的,因为 Web 服务器帐户将尝试验证 Sql Server Express 数据库是否已存在于应用程序的 App_Data 目录中。从 Web 服务器帐户撤消对 App_Data 目录的读取访问权限将阻止提供程序正确确定 Sql Server Express 数据库是否已存在。当提供者试图创建一个已经存在的数据库的副本时,这将导致错误。需要写入访问权限,因为在创建新数据库时会使用 Web 服务器帐户的凭据。 必须在计算机上安装 SQL Server Express。 Web 服务器帐户的进程标识必须具有本地用户配置文件。有关如何为计算机和域帐户创建本地用户配置文件的详细信息,请参阅自述文件。

堆栈跟踪:

[SqlException (0x80131904): 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)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5063578
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity) +341
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +129
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +270
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +5077239
   System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +31
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +76

[HttpException (0x80004005): Unable to connect to SQL Server database.]
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +137
   System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +94
   System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +27
   System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +395

网络配置:

    <?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <connectionStrings>
    <add name="ApplicationServices"
       connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
       providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />

    <authentication mode="Forms">
    <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>

    <membership>
    <providers>
      <clear/>
      <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
         enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
         maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
         applicationName="/" />
    </providers>
    </membership>

    <profile>
    <providers>
      <clear/>
      <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
    </providers>
    </profile>

    <roleManager enabled="false">
    <providers>
      <clear/>
      <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
      <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
    </providers>
    </roleManager>

  </system.web>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

最佳答案

我设法修复了安装 Ms SQL Express 版本的错误。将数据库添加到App_Data 文件夹只支持在PC 中安装Ms SQL Server Express 版本。在我安装 Express Edition 之前,对我没有任何用处,

关于asp.net - 错误。 SQL 网络接口(interface),错误 : 26 - Error Locating Server/Instance Specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18140990/

相关文章:

c# - 如何将 List<T> 传递给 T 实现的另一个类型列表

sql - 检索最后插入的行

sql-server-2008 - 为什么在存储过程调用的参数之一上使用 CONVERT 会出错?

sql-server - 在 SQL Server 中生成 **bearer** CREATE TABLE 和 CREATE PROC 语句

c# - 没有名为 'ASP.NET 4.6.81.0' 的事件日志源。此模块需要 .NET Framework 2.0

c# - asp.net(网络表单)中的 ErrorMessage 和 ValidationSummary

c# - 如何告诉 GridView 在 CellClick 上打开超链接?

sql-server - 使用异常语法的 SQL UPDATE

sql-server - 获取给定年份中所有星期六的日期 - sql server

c# - 如何在传递时修改 DbContext 基本构造函数参数?