我有一个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"/>
但结果没有改变。
EDIT2:
我更新了提供程序的连接字符串,现在我的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和classifieds.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)
“
答案 0 :(得分:3)
@BrianR的建议很好(会员配置指向不存在的连接字符串)。
然而,除此之外,这个问题对于您的托管服务提供商而言过于具体,与堆栈溢出相关。 您应该通过技术支持直接与您的托管服务提供商联系。
您看到的错误意味着IIS / ASP.net无法找到SqlServer。这将是您的连接字符串或主机Web服务器配置错误的结果。这就是为什么这个问题特定于您的主机,不适用于可能通过谷歌找到此问题的其他用户。不同的主机会有所不同。
由于从一个主机到另一个主机的这些潜在配置差异,您确实需要联系它们。您可能已经为此目的提供了技术支持!
您对该问题的后续修改并未更改上述信息。您仍然遇到错误,表明您无法连接到SqlServer。您仍然需要验证与您的托管服务提供商安装SqlExpress,您是否具有访问SqlServer的正确凭据/权限,并且您的两个数据库文件确实存在于具有正确权限的正确位置
即使您的数据库架构不正确,也不会出现此特定错误。所以它必须与SqlServer / SqlExpress的配置,您的数据文件和您的web / config相关。这些设置特定于您的主机,而不是通常可以在stackoverflow上回答的内容。
答案 1 :(得分: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>
答案 2 :(得分:2)
您的托管服务提供商可能没有安装SQLExpress。 (SQLExpress不是dot.net框架的一部分,它是一个不同的产品。)