I don't know why I am getting this error when I deploy my web on server. Is it because the problem with my connection string? Please help me. Thank you!!!
Web.config
<add name="Database1" connectionString="Data Source='170.21.191.85';Initial Catalog='Database1';User ID='sa';Password='123'"/>
Login.aspx.vb
Dim connection As String = System.Configuration.ConfigurationManager.ConnectionStrings("Database1").ConnectionString()
Dim mycon As New SqlConnection(connection)
Stack Trace
[NullReferenceException: Object reference not set to an instance of an object.] WebApplication1.Login.ImageButton2_Click(Object sender, ImageClickEventArgs e) in C:\Users\L30810\Desktop\fyp final.14\WebApplication1\Login.aspx.vb:16 System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +86 System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +115 System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
ImageButton2_Click
Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click
Dim connection As String = System.Configuration.ConfigurationManager.ConnectionStrings("Database1").ConnectionString()
Dim mycon As New SqlConnection(connection)
mycon.Open()
Dim queryString As String = "SELECT Role,StaffName FROM [role] WHERE LoginID ='" + TextBox1.Text + "' and Password='" + TextBox2.Text + "'"
Dim cmd As SqlCommand = New SqlCommand(queryString, mycon)
Dim reader As SqlDataReader = cmd.ExecuteReader()
Dim user1 As String = ""
While reader.Read()
Dim role As String = ""
role = reader.GetString(0)
user1 = reader.GetString(1)
Session("role") = role
End While
If (Session("role") = "SA") Then
Response.Expires = 0
Response.ExpiresAbsolute = Now()
Response.CacheControl = "no-cache"
Session("User") = user1
Response.Redirect("MainPageSA.aspx")
ElseIf (Session("role") = "MGR") Then
Session("User") = user1
Response.Expires = 0
Response.ExpiresAbsolute = Now()
Response.CacheControl = "no-cache"
Response.Redirect("MainPageMGR.aspx")
ElseIf (Session("role") = "Assessor") Then
Session("User") = user1
Response.Expires = 0
Response.ExpiresAbsolute = Now()
Response.CacheControl = "no-cache"
Response.Redirect("MainPageAssessor.aspx")
ElseIf (Session("role") = "MC") Then
Session("User") = user1
Response.Expires = 0
Response.ExpiresAbsolute = Now()
Response.CacheControl = "no-cache"
Response.Redirect("MainPageMC.aspx")
Else
MsgBox("Invalid Username/Password", MsgBoxStyle.OkOnly, "Clinical Peformance Appraisal")
End If
reader.Close()
mycon.Close()
End Sub