简体   繁体   English

无法连接到ASP.NET Web管理工具中的SQL Server数据库

[英]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. 我已经使用aspnet_regsql向导为此配置数据库。 The creation of the database was successful , but i still get the error. 数据库创建成功 ,但是仍然出现错误。

Here is the webconfig so far: 到目前为止,这是webconfig

<?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? 我知道我可能在此xml中缺少一些会员标签吗? Could anyone help me fix the webconfig file? 谁能帮我修复webconfig文件?

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. 在此保存(localdb)\\ MSSQLLocalDB上,我具有由向导aspnet_regsql创建的aspnetdb。

<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的新手。 ASP.Net Membership you mentioned is over 10 to 15 years old. 您提到的ASP.Net成员已有10到15年的历史。 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) ASP.Net成员资格提供程序(使用aspnet_regsql生成表)
  2. ASP.NET Universal Providers ASP.NET通用提供程序
  3. Simple Membership Provider 简单会员资格提供者
  4. ASP.NET Identity (latest one) ASP.NET身份(最新版本)

Since you are also new to ASP.Net Membership, I personally recommend to use ASP.Net Identity. 由于您也是ASP.Net成员身份的新手,因此我个人建议使用ASP.Net身份。 Here is the free ASP.NET MVC 5 Fundamentals course by Scott Allen 这是Scott Allen的免费ASP.NET MVC 5基础课程

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. 借助Integrated Security=SSPI ,我相信您将以网站正在运行的任何帐户(可能是apppool身份帐户)连接到SQL Server。 You should either create a user in SQL and explicitly connect with those credentials, or add the app pool identity to have permissions: 您应该使用SQL创建用户并使用这些凭据进行显式连接,或者添加应用程序池标识以具有权限:

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/ ): 对于本地SQL Server(来自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. 打开SQL Server Management Studio(SSMS)并连接到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) 对于登录名,键入IIS APPPOOL \\ AppPoolName并单击“不要单击搜索”,然后选择“确定”(如果执行搜索,它将解析为具有ServerName \\ AppPool Name的帐户,而SQL将无法解析该帐户的SID,因为它是虚拟的)
  • Select the defaults for the account and select OK to close dialog 选择该帐户的默认值,然后选择确定以关闭对话框

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法连接到ASP.NET网站管理工具中的SQL Server数据库 - Unable to connect to SQL Server database in asp.net Web Site Administration Tool 无法连接到SQL Server数据库(ASP.NET C#) - Unable to connect to SQL Server Database (ASP.NET C#) “无法连接到SQL Server数据库”-ASP.NET配置 - “Unable to connect to SQL Server database” - ASP.NET configuration asp.net Web API无法使用非管理员用户连接到Azure SQL数据库 - asp.net web api cannot connect to Azure SQL database with non-admin user 无法连接到 web 服务器 IIS Express - ASP.NET CORE - Unable to connect to web server IIS Express - ASP.NET CORE ASP.NET 5 MVC:无法连接到 Web 服务器“IIS Express” - ASP.NET 5 MVC: unable to connect to web server 'IIS Express' 如何连接到SQL Server并通过ASP.NET Web窗体查看数据库中的数据? - How can I connect to SQL Server and view the data in the database through ASP.NET Web Form? ASP.Net Web应用程序连接到主机SQL数据库 - ASP.Net web application connect to host SQL DataBase ASP.net应用程序无法连接到SQL Server命名实例 - ASP.net application unable to connect to SQL Server named instance 无法将 ASP.NET 应用程序连接到 Docker 上的 SQL 服务器 - Unable to connect ASP.NET app to SQL Server on Docker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM