This is my page_loads event code and iam getting the Exception pasted below the code.
---------------------------------------------
Protected
Sub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)IfNot Page.IsPostBackThenDim myconnectionAsNew SqlConnection("Data Source=localhost\SQLEXPRESS;initial catalog = safetydata.mdf;Integrated Security=True;User Instance=True")Dim strSQLAsString ="SELECT Incident_Id,Emp_No From Report_Incident"Dim mycommandAsNew SqlCommand(strSQL, myconnection)myconnection.Open()
Dim readerAs SqlDataReader = mycommand.ExecuteReader()Dim chartAsNew PieChart
chart.DataSource = reader
chart.DataXValueField =
"Incident_id"chart.DataYValueField =
"Emp_No"chart.DataBind()
chart.DataLabels.Visible =
True
ChartControl1.Charts.Add(chart)
ChartControl1.RedrawChart()
myconnection.Open()
EndIfEndSub
--------------------------------------
EXCEPTION IS BELOW
Cannot open database "mydatabase.mdf" requested by the login. The login failed.
Login failed for user 'myusername'.
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 database "safetydata.mdf" requested by the login. The login failed.
Login failed for user 'myusername'.
Source Error:
Line 18: Dim strSQL As String = "SELECT Incident_Id,Emp_No From Report_Incident"Line 19: Dim mycommand As New SqlCommand(strSQL, myconnection)Line 20: myconnection.Open()Line 21: Dim reader As SqlDataReader = mycommand.ExecuteReader()Line 22:
Source File:C:\Incident Reporting System--Trial Version\WebChart.aspx Line:20
Stack Trace:
[SqlException (0x80131904): Cannot open database "safetydata.mdf" requested by the login. The login failed.Login failed for user 'myusername'.] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +171 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +199 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2305 System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +34 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +606 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +193 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +501 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +429 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +70 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +512 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +85 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +89 System.Data.SqlClient.SqlConnection.Open() +160 ASP.webchart_aspx.Page_Load(Object sender, EventArgs e) in C:\Incident Reporting System--Trial Version\WebChart.aspx:20 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +45 System.Web.UI.Control.OnLoad(EventArgs e) +80 System.Web.UI.Control.LoadRecursive() +49 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3745
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.
Hi Nick,
Based on the connection string, we can see that you're currently using the the Windows integrated authentication to connection to the .mdf file. And the exception message reveals your windows identity is not a valid user to this database.
In this case, you can try to check if you have added your identity to the database login list. Also, please check if you have granted enough permission to this username.
HTH.