我添加了對以下靜態ROLES類的引用,以便將角色分配給JOIN網站的人員。當我按下JOIN ASP.Net控件上的按鈕時,我測試了代碼和應用程序。當然,我立即嘗試調試以發現問題,但是我無法再訪問SQL Express ASPNETDB.mdf - 錯誤如下所示。提前致謝。無法訪問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="data source=.;attachdbfilename=|DataDirectory|\FCGuide.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" 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 loggedIn = Membership.GetUser(); 線51:如果(的loggedIn == NULL) 52行:{
源文件:H:\ FCGuide \ FCGuide \ default.aspx.cs行:50
堆棧跟蹤:
[SqlException(0x80131904):無法打開用戶默認數據庫。登錄失敗。 用戶登錄失敗'SFP \蘇珊。] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException異常,布爾breakConnection)5064474 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()+234 System.Data。 SqlClient.TdsParser.Run(runBehavior runBehavior,SqlCommand的cmdHandler,SqlDataReader的數據流,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)2275 System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(布爾enlistOK)35 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin( ServerInfo serverInfo,String newPassword,Boolean ignoreSniOpenTimeout,TimeoutTimer超時,SqlConnection擁有對象)+183 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,String newPassword布爾redirectedUserInstance,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 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 系統。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 outerConnection,DbConnectionFactory connectionFactory的) +126 System.Data.SqlClient.SqlConnection.Open()+125 System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext上下文,Boolean revertImpe (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中的FCGuide._default.Page_Load(Object sender,EventArgs e)。 CS:50 錯誤幫助(IntPtr的FP,對象O,對象噸,EventArgs的)14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(對象發件人,EventArgs的)35 系統。 Web.UI.Control.OnLoad(EventArgs e)+91 System.Web.UI.Control.LoadRecursi VE()+74 System.Web.UI.Page.ProcessRequestMain(布爾includeStagesBeforeAsyncPoint,布爾includeStagesAfterAsyncPoint)2207
您是否已通過在服務器資源管理器中添加數據庫進行連接? – coder
是的,我可以在服務器資源管理器中打開數據庫並查看錶格及其內容。 – Susan
可能會解決您的錯誤http://social.msdn.microsoft.com/forums/en-US/sqlsecurity/thread/b32c862a-799c-43c4-a731-c4811078c8bd/ – coder