2

我在下面添加了对静态 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' 登录失败。

网络配置:

<?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 = featuresList4[0].CITY.CITY_NAME; 第 49 行:第 50 行:MembershipUser loggedIn = Membership.GetUser(); 第 51 行:如果 (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, 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,

4

2 回答 2

0

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

于 2011-11-26T15:30:38.160 回答
0

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

于 2012-04-09T17:16:54.753 回答