[英]Error: 26 - Error Locating Server/Instance Specified after hosting to a web server
I developed website using Asp.Net MVC C#, and everything works fine locally on my pc in Visual Studio. 我使用Asp.Net MVC C#开发了网站,并且在Visual Studio中在我的PC上本地一切正常。 After hosting the website to the server I got Error: 26 - Error Locating Server/Instance Specified . 将网站托管到服务器后,出现错误:26-查找指定的服务器/实例时出错 。 The error shows up when I try to login to the website, after I press the login button. 按下登录按钮后,当我尝试登录网站时会显示错误。 I think the problem is with automatically created authentication database ASPNETDB.mdf in App_Data folder and the connection string to that database. 我认为问题在于在App_Data文件夹中自动创建了身份验证数据库ASPNETDB.mdf以及该数据库的连接字符串 。 I was searching and trying different already published solutions before but I still can't solve the error.I tried different solutions to solve that in web.config, but unsucsessfully. 我之前一直在搜索并尝试其他已经发布的解决方案,但仍然无法解决该错误。我尝试了不同的解决方案来解决web.config中的问题,但未成功。
The solution I am looking is somewhere in configuring my ASP.NET Identity membership system, which works great locally on my pc and not after the upload. 我正在寻找的解决方案是在配置ASP.NET Identity成员资格系统中的某处,该系统在我的PC上本地运行良好,而不是在上传之后运行。
I already have one database with one connection string to that database (BicycleWorldShop2). 我已经有一个数据库,并且该数据库具有一个连接字符串(BicycleWorldShop2)。 Should I publish ASPNETDB.mdf as a second database and add a second connection string in web.config file? 我应该将ASPNETDB.mdf作为第二个数据库发布,并在web.config文件中添加第二个连接字符串吗? How should I configure membership correctly? 如何正确配置成员资格?
This is the code of my Web.config file. 这是我的Web.config文件的代码。
<?xml version="1.0" encoding="utf-8"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=301880 --> <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections> <appSettings> <add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> <system.web> <compilation debug="true" targetFramework="4.6.1" /> <httpRuntime targetFramework="4.6.1" /> <globalization culture="en-IN" /> <authentication mode="Forms"> <forms loginUrl="~/Accounts/LogOn" timeout="2880" /> </authentication> <customErrors mode="Off" /> <membership> <providers> <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/> </providers> </membership> <profile> <providers> <add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> </providers> </profile> <roleManager enabled="true"> <providers> <clear/> <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> <add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> </providers> </roleManager> </system.web> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> </dependentAssembly> </assemblyBinding> </runtime> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework> <connectionStrings> <add name="BicycleWorldShop2" connectionString="Data Source=WW-PC\\SqlExpress;Initial Catalog=BicycleWorldShop;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration>
Does anyone how to solve this? 有人解决这个问题吗?
Please, for any help, I waste a lot of time in trying to solve this error! 请寻求任何帮助,我会浪费大量时间来尝试解决此错误!
I suggest to backup ASPNETDB.mdf and restore as a separate database on the hosting server. 我建议备份ASPNETDB.mdf并将其还原为托管服务器上的单独数据库。 Then create second connectionstring under <connectionStrings>
web.config section. 然后在<connectionStrings>
web.config部分下创建第二个connectionstring。
Lastly, update the connectionstringName
property on membership, profile and roleManager providers. 最后,更新成员资格,概要文件和roleManager提供程序上的connectionstringName
属性。
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="SecondConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
Alternate Approach for adding ASPNETDB Object to same database 将ASPNETDB对象添加到同一数据库的替代方法
On your computer, type %WINDIR%\\Microsoft.Net\\Framework\\
in run command and then go to v4.0... folder. 在您的计算机上,在运行命令中键入%WINDIR%\\Microsoft.Net\\Framework\\
,然后转到v4.0 ...文件夹。 In this folder, you will find T-SQL script files for creating Membership, Profile and Role schema. 在此文件夹中,您将找到用于创建成员资格,配置文件和角色架构的T-SQL脚本文件。 You will require to execute the scripts on your hosting provider database. 您将需要在托管服务提供商数据库上执行脚本。
You will need to first execute the InstallCommon.sql
for creating the common tables. 您将需要首先执行InstallCommon.sql
以创建公用表。 Then you execute the following scripts. 然后,执行以下脚本。
Note: All above mentioned scripts will assume that you have database named aspnetdb
so you will require to open each sql file in text editor and then change the following lines of code to match your database name: 注意:上述所有脚本均假定您具有名为aspnetdb
数据库,因此您将需要在文本编辑器中打开每个sql文件,然后更改以下代码行以匹配您的数据库名称:
SET @dbname = N'aspnetdb'
USE [aspnetdb]
PS Do you really need AspNetWindowsTokenRoleProvider
? PS ,您真的需要AspNetWindowsTokenRoleProvider
吗? Also, add <clear/>
in membership and profile providers section 另外,在成员资格和个人资料提供者部分中添加<clear/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.