gpt4 book ai didi

c# - 无法打开登录请求的数据库 "aspnetdb"。登录失败

转载 作者:太空狗 更新时间:2023-10-30 01:25:50 26 4
gpt4 key购买 nike

我可以使用我的登录名登录和浏览。但是只要我在我的页面上按下一个超链接,它就会抛出这个:

Cannot open database "aspnetdb" requested by the login. The login failed.

用户“DIMA-00AA1DA557\Dima”登录失败。

描述:当前网络请求执行过程中出现未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.Data.SqlClient.SqlException:无法打开登录请求的数据库“aspnetdb”。登录失败。用户“DIMA-00AA1DA557\Dima”登录失败。

为什么这样做/...

我认为我的连接字符串和成员(member)提供程序一切正常:

<connectionStrings>
<clear />
<add name="LocalSqlServer" providerName="System.Data.SqlClient" connectionString="Data Source=localhost;Integrated Security=SSPI; Initial Catalog=aspnetdb" />
<add name="YourGuruDB" connectionString="Data Source=DIMA-00AA1DA557;Initial Catalog=model;Integrated Security=True"/>
<add name="modelConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename='D:\Documents and Settings\Dima\My Documents\Visual Studio 2010\WebSites\WebSite10\App_Data\ASPNETDB.MDF';Integrated Security=True;User Instance=True;Trusted_Connection=Yes;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<authentication mode="Forms">
<forms name=".MyCookie"
loginUrl="~/Registration.aspx"
protection="All"
timeout="30" path="/" >
<credentials passwordFormat="MD5">
<user name="user" password="ca064d0730abfeb09e383a0e82e65f73"/>
</credentials>
</forms>
</authentication>

<roleManager enabled="true"/>

<membership defaultProvider="MyMembershipProvider">
<providers>
<clear/>
<add name="MyMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="modelConnectionString"
minRequiredPasswordLength="1"
minRequiredNonalphanumericCharacters="0"
enablePasswordReset="true"
maxInvalidPasswordAttempts="1000"
passwordAttemptWindow="4000"
enablePasswordRetrieval="true"
requiresUniqueEmail="false"
passwordFormat="Encrypted"
applicationName="/WebSite10" />
</providers>
</membership>

最佳答案

正如“Rune FS”在评论中指出的那样,您已经将数据库连接字符串配置为使用集成身份验证,这是一件好事,因为您没有在配置文件中存储明确的用户名/密码。

但是,您需要知道它从何处获取“集成”凭据 - 在这种情况下,运行 IIS(或 VS Dev Server)的用户的凭据用于连接到数据库 -如果它使用您的 Windows 登录名,我假设您使用的是 IIS Express 或 VS 开发服务器?

我相信您遇到的问题是,当您启用了角色管理器时,您还没有配置它,并且您保留了默认值 LocalSqlServer启用的连接字符串还指向名为 aspnetdb 的数据库- 默认情况下,这将尝试使用使用 LocalSqlServer 连接的默认角色管理器提供程序。

修改<rolemanager />要读取的元素:

<rolemanager enabled="true" defaultProvider="MyRoleProvider" >
<providers>
<clear />
<add name="MyRoleProvider"
applicationName="/"
connectionStringName="modelConnectionString"
type="System.Web.Security.SqlRoleProvider" />
</providers>
</rolemanager>

我还建议删除 LocalSqlServer连接字符串,如果您不使用它来避免这种混淆。

关于c# - 无法打开登录请求的数据库 "aspnetdb"。登录失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6152875/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com