简体   繁体   中英

Unable to connect to SQL Server database in ASP.NET Web Admin Tool

Like the title says I am trying to make some roles for a site that i am making.

Whenever I enter the security tab the error in the title is displayed.

I have used the aspnet_regsql wizard to configure a database for this purpose. The creation of the database was successful , but i still get the error.

Here is the webconfig so far:

<?xml version="1.0"?>
<configuration>
 <configSections>
   <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
     <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
     <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
   </sectionGroup>

 </configSections>
 <entityFramework>
  <contexts>
   <context type="ContosoUniversity.DAL.SchoolContext, ContosoUniversity">
     <databaseInitializer type="ContosoUniversity.DAL.SchoolInitializer, ContosoUniversity" />
   </context>
  </contexts>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
   <parameters>
     <parameter value="v11.0" />
   </parameters>
  </defaultConnectionFactory>
  <providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  </providers>
 </entityFramework>
  <connectionStrings>
    <add name="SchoolContext" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=ContosoUniversity1;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <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.webPages.razor>
   <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
    <namespaces>
     <add namespace="System.Web.Mvc" />
     <add namespace="System.Web.Mvc.Ajax" />
     <add namespace="System.Web.Mvc.Html" />
     <add namespace="System.Web.Optimization"/>
     <add namespace="System.Web.Routing" />
     <add namespace="TESTMVC" />
    </namespaces>
  </pages>
 </system.web.webPages.razor>


 <system.webServer>
  <handlers>
   <remove name="BlockViewHandler"/>
   <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
  </handlers>
 </system.webServer>

  <system.web>
   <compilation>
    <assemblies>
     <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </assemblies>
   </compilation>

 </system.web>
</configuration>

I know I am probably missing some membership tag in this xml? Could anyone help me fix the webconfig file?

This connection string is used for a page that displays some stuff from this database. On this save (localdb)\\MSSQLLocalDB i have the aspnetdb made by the wizard aspnet_regsql.

<connectionStrings>
  <add name="SchoolContext" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=ContosoUniversity1;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
</connectionStrings>

Base on your comment you are new to ASP.NET Membership. ASP.Net Membership you mentioned is over 10 to 15 years old. Microsoft has replaced it few others in those years.

Here is the history -

  1. ASP.Net Membership Provider (which uses aspnet_regsql to generate tables)
  2. ASP.NET Universal Providers
  3. Simple Membership Provider
  4. ASP.NET Identity (latest one)

Since you are also new to ASP.Net Membership, I personally recommend to use ASP.Net Identity. Here is the free ASP.NET MVC 5 Fundamentals course by Scott Allen

With Integrated Security=SSPI , I believe you are going to connect to SQL server as whatever account the web site is running under, likely an apppool identity account. You should either create a user in SQL and explicitly connect with those credentials, or add the app pool identity to have permissions:

For a local SQL Server (from https://blogs.msdn.microsoft.com/ericparvin/2015/04/14/how-to-add-the-applicationpoolidentity-to-a-sql-server-login/ ):

  • Open SQL Server Management Studio (SSMS) and connect to the SQL Server. Open the Security folder at the server level and not the security folder for the database.
  • Right click on the logins and select New Login.
  • For the login, type IIS APPPOOL\\AppPoolName and DO NOT CLICK SEARCH and select OK (If a search is executed, it will resolve to an account with ServerName\\AppPool Name and SQL will be unable to resolve the account's SID since it is virtual)
  • Select the defaults for the account and select OK to close dialog

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