简体   繁体   中英

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. After hosting the website to the server I got Error: 26 - Error Locating Server/Instance Specified . 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. 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.

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.

I already have one database with one connection string to that database (BicycleWorldShop2). Should I publish ASPNETDB.mdf as a second database and add a second connection string in web.config file? How should I configure membership correctly?

This is the code of my Web.config file.

 <?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> 
What should I change in my code?

Does anyone how to solve this?

Please, for any help, I waste a lot of time in trying to solve this error!

The error: 在此处输入图片说明

I suggest to backup ASPNETDB.mdf and restore as a separate database on the hosting server. Then create second connectionstring under <connectionStrings> web.config section.

Lastly, update the connectionstringName property on membership, profile and roleManager providers.

<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

On your computer, type %WINDIR%\\Microsoft.Net\\Framework\\ in run command and then go to v4.0... folder. In this folder, you will find T-SQL script files for creating Membership, Profile and Role schema. 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. Then you execute the following scripts.

  1. InstallMembership.sql
  2. InstallProfile.SQL
  3. InstallRoles.sql

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:

SET @dbname = N'aspnetdb'
USE [aspnetdb]

PS Do you really need AspNetWindowsTokenRoleProvider ? Also, add <clear/> in membership and profile providers section

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM