无法访问 ASPNETDB.mdf

发布于 2024-12-18 04:28:53 字数 6624 浏览 0 评论 0原文

我添加了对下面的静态 ROLES 类的引用,以将角色分配给加入网站的人员。我测试了代码,当我按下 JOIN ASP.Net 控件上的按钮时,应用程序挂起。当然,我立即尝试调试来查找问题,但我无法再访问 SQL Express ASPNETDB.mdf - 下面列出了错误。提前致谢。

**The code-behind in the Join.aspx file:**
    public partial class Join : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MembershipUser loggedIn = Membership.GetUser();
            if (loggedIn == null)
            {
                return;
            }
            else
            {
                Session["userName"] = loggedIn.UserName;
                Roles.AddUserToRole(loggedIn.ToString(), "MEMBER");

            }
        }

    }

错误消息:无法打开用户默认数据库。登录失败。用户“SFP\Susan”登录失败。

Web 配置:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <appSettings>
        <add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />
    </appSettings>
    <system.webServer>
        <handlers>
            <remove name="ChartImageHandler" />
            <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
                path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </handlers>
    </system.webServer>
    <system.web>
        <authorization>
            <allow roles="ADMIN" />
            <allow roles="MEMBER" />
            <allow roles="GUEST" />
            <allow roles="RESTAURANT" />
        </authorization>
        <roleManager enabled="true" />
        <authentication mode="Forms" />
        <httpHandlers>
            <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                validate="false" />
        </httpHandlers>
        <pages>
            <controls>
                <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
                    assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            </controls>
        </pages>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
  <connectionStrings>
    <add name="FCGuideEntities" connectionString="metadata=res://*/FCGuide.csdl|res://*/FCGuide.ssdl|res://*/FCGuide.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;attachdbfilename=|DataDirectory|\FCGuide.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

堆栈跟踪

无法打开用户默认数据库。登录失败。 用户“SFP\Susan”登录失败。 描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.Data.SqlClient.SqlException:无法打开用户默认数据库。登录失败。 用户“SFP\Susan”登录失败。

源错误:

第 48 行:restCity4.Text =featuredList4[0].CITY.CITY_NAME; 第 49 行: 第 50 行:MembershipUser 登录 = Membership.GetUser(); 第 51 行:if (loggedIn == null) 第 52 行:{

源文件:H:\FCGuide\FCGuide\default.aspx.cs 行:50

堆栈跟踪:

[SqlException (0x80131904):无法打开用户默认数据库。登录失败。 用户“SFP\Susan”登录失败。] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection)+5064474 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSetbulkCopyHandler,TdsParserStateObject stateObj)+2275 System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(布尔 enlistOK) +35 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,字符串newPassword,布尔值ignoreSniOpenTimeout,TimeoutTimer超时,SqlConnection owningObject)+183 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,字符串newPassword,布尔重定向UserInstance,SqlConnection owningObject,SqlConnectionString connectionOptions,TimeoutTimer超时)+239 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject,TimeoutTimer超时,SqlConnectionString connectionOptions,字符串newPassword,布尔redirectedUserInstance)+195 System.Data.SqlClient.SqlInternalConnectionTds ..ctor(DbConnectionPoolIdentity标识,SqlConnectionString connectionOptions,对象providerInfo,字符串newPassword,SqlConnection owningObject,布尔redirectedUserInstance)+232 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions选项,对象池GroupProviderInfo,DbConnectionPool池,DbConnection owningConnection)+185 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection,DbConnectionPool池,DbConnectionOptions选项)+33 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)+524 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)+66 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)+479 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)+108 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection externalConnection,DbConnectionFactory 连接工厂)+126 System.Data.SqlClient.SqlConnection.Open() +125 System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext上下文,布尔revertImpersonate)+95 System.Web.DataAccess.SqlConnectionHelper.GetConnection(字符串connectionString,布尔revertImpersonation)+206 System.Web.Security.SqlMembershipProvider.GetUser(字符串用户名,布尔值 userIsOnline)+1169 System.Web.Security.Membership.GetUser(字符串用户名,布尔值 userIsOnline)+63 System.Web.Security.Membership.GetUser() +19 H:\FCGuide\FCGuide\default.aspx.cs:50 中的 FCGuide._default.Page_Load(对象发送者,EventArgs e) System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,对象o,对象t,EventArgs e)+14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(对象发送者,EventArgs e)+35 System.Web.UI.Control.OnLoad(EventArgs e)+91 System.Web.UI.Control.LoadRecursive() +74 System.Web.UI.Page.ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,布尔 includeStagesAfterAsyncPoint)+2207

I added the reference to the static ROLES class below to assign the role to people that JOIN the website. I tested the code and the application hung when I pressed the button on the JOIN ASP.Net control. Of course, I immediately tried debug to find the problem but I could no longer access the SQL Express ASPNETDB.mdf - the error is listed below. Thanks in advance.

**The code-behind in the Join.aspx file:**
    public partial class Join : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MembershipUser loggedIn = Membership.GetUser();
            if (loggedIn == null)
            {
                return;
            }
            else
            {
                Session["userName"] = loggedIn.UserName;
                Roles.AddUserToRole(loggedIn.ToString(), "MEMBER");

            }
        }

    }

ERROR MESSAGE: Cannot open user default database. Login failed. Login failed for user 'SFP\Susan'.

Web Config:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <appSettings>
        <add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />
    </appSettings>
    <system.webServer>
        <handlers>
            <remove name="ChartImageHandler" />
            <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
                path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </handlers>
    </system.webServer>
    <system.web>
        <authorization>
            <allow roles="ADMIN" />
            <allow roles="MEMBER" />
            <allow roles="GUEST" />
            <allow roles="RESTAURANT" />
        </authorization>
        <roleManager enabled="true" />
        <authentication mode="Forms" />
        <httpHandlers>
            <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                validate="false" />
        </httpHandlers>
        <pages>
            <controls>
                <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
                    assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            </controls>
        </pages>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
  <connectionStrings>
    <add name="FCGuideEntities" connectionString="metadata=res://*/FCGuide.csdl|res://*/FCGuide.ssdl|res://*/FCGuide.msl;provider=System.Data.SqlClient;provider connection string="data source=.;attachdbfilename=|DataDirectory|\FCGuide.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

The STACK TRACE

Cannot open user default database. Login failed.
Login failed for user 'SFP\Susan'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Cannot open user default database. Login failed.
Login failed for user 'SFP\Susan'.

Source Error:

Line 48: restCity4.Text = featuredList4[0].CITY.CITY_NAME;
Line 49:
Line 50: MembershipUser loggedIn = Membership.GetUser();
Line 51: if (loggedIn == null)
Line 52: {

Source File: H:\FCGuide\FCGuide\default.aspx.cs Line: 50

Stack Trace:

[SqlException (0x80131904): Cannot open user default database. Login failed.
Login failed for user 'SFP\Susan'.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5064474
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +183
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +239
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
System.Data.SqlClient.SqlConnection.Open() +125
System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +95
System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +206
System.Web.Security.SqlMembershipProvider.GetUser(String username, Boolean userIsOnline) +1169
System.Web.Security.Membership.GetUser(String username, Boolean userIsOnline) +63
System.Web.Security.Membership.GetUser() +19
FCGuide._default.Page_Load(Object sender, EventArgs e) in H:\FCGuide\FCGuide\default.aspx.cs:50
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难得心□动 2024-12-25 04:28:54

检查用户的默认数据库是否可访问,以及该数据库中是否有您登录的用户。您可以从 SSMS 检查您的默认数据库是什么。

Check if user's default database is accessible and there is a user for your login in that database. You can check what's your default database from SSMS.

你穿错了嫁妆 2024-12-25 04:28:54

我无法打开它,因为我有 SQL2008,而数据库 ASPNETDB.MDF 实际上来自 SQL2008-R2。在 R2 中打开它,然后从那里继续。

I couldnt open it because I had SQL2008, and the database ASPNETDB.MDF was actually from SQL2008-R2. Got it opened in R2, then proceeded from there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文