السلام عليكم ورحمة الله وبركاته..
أريد معرفة حل هذا Error وما هو سببه..
Server Error in '/login' Application.
________________________________________
ExecuteReader: Connection property has not been initialized.
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.InvalidOperationException: ExecuteReader: Connection property has not been initialized.
Source Error:
Line 22: conn.Connection = Connection
Line 23: conn.CommandText = sql
Line 24: Return conn.ExecuteReader
Line 25: End Function
Line 26: Public Shared Function dispose()
Source File: c:\inetpub\wwwroot\login\DAL.vb Line: 24
Stack Trace:
[invalidOperationException: ExecuteReader: Connection property has not been initialized.]
System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean executing)
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
System.Data.SqlClient.SqlCommand.ExecuteReader()
login.DAL.excuteSql(String sql) in c:\inetpub\wwwroot\login\DAL.vb:24
login.SignOn.login(String username, String password) in c:\inetpub\wwwroot\login\SignOn.aspx.vb:41
login.SignOn.butSignOn_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\login\SignOn.aspx.vb:123
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
علما بأن الكود الموجود في DAL.vb هو:
Public Class DAL
Private Shared Connection As System.Data.SqlClient.SqlConnection
Public Shared Function initialize() As Boolean
If Connection Is Nothing Then
Dim Connection As New SqlClient.SqlConnection
Dim strConnectionString As String = "Server=SALMA-H1STH3TGR;DataBase=CASFSU;Trusted_Connection=True"
Connection.ConnectionString = strConnectionString
Connection.Open()
ElseIf Connection.State <> ConnectionState.Open Then
Connection.ConnectionString = "Server=SALMA-H1STH3TGR;DataBase=CASFSU;Trusted_Connection=True"
Connection.Open()
End If
Return True
End Function
Public Shared Function excuteSql(ByVal sql As String) As SqlClient.SqlDataReader
initialize()
Dim conn As New SqlClient.SqlCommand
conn.CommandType = CommandType.Text
conn.Connection = Connection
conn.CommandText = sql
Return conn.ExecuteReader
End Function
Public Shared Function dispose()
Connection.Close()
Connection.Dispose()
End Function
End Class