【问题标题】:provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified提供程序:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例
【发布时间】:2012-07-25 08:40:54
【问题描述】:

我有一个 asp .net 2.0 Web 应用程序。它在我的本地机器上运行良好。我将该网站发布给了我的托管服务提供商,但它给出了以下错误:

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)

我的 web.config 文件中的设置如下:

 <membership>
  <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
  </providers>
</membership>

和

<add name="classifiedsConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CLASSIFIEDSDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>

所有 mdf ldf 文件都上传到主机。我在 stackoverflow 上检查了许多类似的问题,但解决方案对我没有帮助。以这种方式使用 sqlexpress 有错吗?我该如何解决这个问题?

任何帮助将不胜感激。谢谢 谢谢。

编辑:

web.config 文件中没有 LocalSQLServer 连接字符串。但要确保我尝试添加此连接字符串

<add name="LocalSqlServer" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>

但结果没有改变。

编辑2:

我更新了提供者的连接字符串,现在我的 web.config 文件如下:

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <location path="Admin">
    <system.web>
      <authorization>
        <allow roles="Administrators"/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>
  <location path="PostAd.aspx">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>
  <location path="EditPhotos.aspx">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>
  <location path="MyAds.aspx">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>
  <location path="MyProfile.aspx">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>
  <system.web>
    <customErrors mode="Off"/>
    <pages styleSheetTheme="Red"/>
    <authentication mode="Forms"/>
    <membership>
      <providers>
      <clear/>
      <add name="AspNetSqlMembershipProvider"
           type="System.Web.Security.SqlMembershipProvider, System.Web,     Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
           connectionStringName="membershipConnection"
           enablePasswordRetrieval="false"
           enablePasswordReset="true"
           requiresQuestionAndAnswer="true"
           applicationName="/"
           requiresUniqueEmail="true"
           passwordFormat="Hashed"
           maxInvalidPasswordAttempts="5"
           minRequiredPasswordLength="7"
           minRequiredNonalphanumericCharacters="1"
           passwordAttemptWindow="10"
           passwordStrengthRegularExpression=""/>
    </providers>
    </membership>
    <profile enabled="true">
      <properties>
        <add name="FirstName" type="System.String"/>
        <add name="LastName" type="System.String"/>
        <add name="MemberId" defaultValue="0" type="System.Int32"/>
        <group name="Core"/>
      </properties>
    </profile>
    <roleManager enabled="true"/>
    <compilation debug="true"/>
    <siteMap defaultProvider="RoleEnabled_AspNetXmlSiteMapProvider" enabled="true">
      <providers>
        <clear/>
        <add name="RoleEnabled_AspNetXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="web.sitemap" securityTrimmingEnabled="true"/>
      </providers>
    </siteMap>
  </system.web>
  <connectionStrings>
    <add name="classifiedsConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CLASSIFIEDSDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
<add name="membershipConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>      
</configuration>

并且我在 May app_data 文件夹中有 aspnetdb.mdf 和分类文件.mdf 文件,但它仍然无法正常工作。我得到的错误的全文是:

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)"

【问题讨论】:

  • 主机服务器(web或machine.config)上是否有名为LocalSqlServer的连接字符串?
  • @JohannBlais 我编辑了我的问题。请检查。没有 localSqlServer 连接字符串,但这种方式在我的本地机器上工作正常。我错过了什么吗?

标签: asp.net visual-studio-2008 sql-server-express mdf


【解决方案1】:

@BrianR 的建议很好(成员资格配置指向一个不存在的连接字符串)。

但是,除此之外,这个问题对于您的托管服务提供商来说实在是太具体了,因此无法在此处与堆栈溢出相关。 您应该通过技术支持直接联系您的托管服务提供商。

您看到的错误意味着 IIS/ASP.net 找不到 SqlServer。这将是您的连接字符串或主机 Web 服务器配置错误的结果。这就是为什么这个问题特定于您的主机,不适用于可能通过谷歌找到这个问题的其他用户。不同的主机会有所不同。

  • 有些主机将安装完整的 SqlServer,有些 只会有 SqlExpress。完整版 SqlServer 不使用相同的默认实例名称安装,可能存在其他配置差异。
  • 出于安全原因或其他系统管理原因,某些主机可能会从默认值更改实例名称,例如“SQLEXPRESS”。 (即使安装了SqlExpress,也不一定意味着可以通过'./SQLEXPRESS'访问)
  • 有些主机使用独立的数据库服务器(不在同一 Windows 服务器实例作为您的网站),您可能需要包含一个 机器路径、IP 地址、端口号、安全凭证或其他详细信息 访问它。如果是这种情况,您的房东会向您提供此信息。有时会记录在案,一些较小的主机可能会要求您提交支持票(如果有疑问,请获取支持票!)。

由于一台主机与另一台主机之间存在这些潜在的配置差异,您确实需要与他们联系。您可能为此提供了技术支持!

编辑#1

您对问题的后续编辑并未更改上述信息。您仍然遇到提示您无法连接到 SqlServer 的错误。您仍然需要验证 与您的托管服务提供商 是否安装了 SqlExpress,您拥有访问 SqlServer 的正确凭据/权限,并且您的两个数据库文件确实存在于正确的位置并具有正确的权限.

即使您的数据库架构不正确,也不会出现此特定错误。所以它必须与SqlServer/SqlExpress的配置、你的数据文件和你的web/config有关。这些设置是特定于您的主机的,通常无法在 stackoverflow 上回答。

【讨论】:

    【解决方案2】:

    在您的会员提供商信息中,您需要将 connectionStringName 更改为“classifiedsConnection”。还要确保您的 CLASSIFIEDSDB.mdf 文件实际上位于主机上的 App_Data 文件夹中。

    <membership defaultProvider="AspNetSqlMembershipProvider">
       <providers>
          <clear/>
          <add name="AspNetSqlMembershipProvider"
               type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
               connectionStringName="classifiedsConnection"
               enablePasswordRetrieval="false"
               enablePasswordReset="true"
               requiresQuestionAndAnswer="true"
               applicationName="/"
               requiresUniqueEmail="true"
               passwordFormat="Hashed"
               maxInvalidPasswordAttempts="5"
               minRequiredPasswordLength="7"
               minRequiredNonalphanumericCharacters="1"
               passwordAttemptWindow="10"
               passwordStrengthRegularExpression=""/>
        </providers>
    </membership>
    

    【讨论】:

    • 了解您使用的托管公司可能会有所帮助?
    • 我刚刚对我的答案进行了编辑,添加了 defaultProvider 属性。我怀疑这是您的问题的原因,但是一旦您当前的问题得到解决,它将使您免于另一个错误。
    • 我有同样的问题,但是我怎么知道主机支持的提供程序是什么,我在管理文件夹的 web.config 中尝试了上面的代码然后我得到了错误:使用一个错误是错误的在应用程序级别之外注册为 allowDefinition='MachineToApplication' 的部分。此错误可能是由于未在 IIS 中将虚拟目录配置为应用程序
    【解决方案3】:

    您的托管服务提供商可能没有安装 SQLExpress。 (SQLExpress 不是 dot.net 框架的一部分,它是一个不同的产品。)

    【讨论】:

    • 您的设置对于“标准安装”是正确的...您的托管服务提供商可能有不同的设置。就像 Ben 说的那样...... SQLExpress 实例可能有不同的名称,在不同的计算机上,您的提供者可能需要您“请求访问”该服务。我会建议您联系您的托管服务提供商的客户支持。
    猜你喜欢
    • 1970-01-01
    • 2014-05-31
    • 2011-01-26
    • 1970-01-01
    • 2016-02-26
    • 2013-08-11
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多