无法访问ASPNETDB.mdf

时间:2011-11-26 14:41:33

标签: c# asp.net sql aspnetdb

我添加了对下面静态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>

STACK TRACE

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

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

来源错误:

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

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

堆栈追踪:

[SqlException(0x80131904):无法打开用户默认数据库。登录失败。 用户'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选项,Object poolGroupProviderInfo,DbConnectionPool池,DbConnection owningConnection)+185    System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection,DbConnectionPool pool,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 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    H:\ FCGuide \ FCGuide \ default.aspx.cs中的FCGuide._default.Page_Load(Object sender,EventArgs e):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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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