서버에 웹을 배포 할 때 왜이 오류가 발생하는지 알 수 없습니다. 연결 문자열에 문제가 있기 때문입니까? 도와주세요. 고맙습니다!!!개체 참조가 개체의 인스턴스로 설정되지 않았습니다.
의 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)
스택 추적
[NullReferenceException이 :. 개체의 인스턴스로 설정되지 않은 개체 참조] C : \ Users \ L30810 \ Desktop \ fyp fina의 WebApplication1.Login.ImageButton2_Click (Object sender, ImageClickEventArgs e) (ImageEventArgs) +86 System.Web.UI.WebControls.ImageButton.RaisePostBackEvent (String eventArgument) +115 System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent (문자열 eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent (IPostBackEventHandler sourceControl, 문자열 eventArgument) +11 System.Web.UI .Page.RaisePostBackEvent (NameValueCollection은 postData를) +33 System.Web.UI.Page.ProcessRequestMain (부울 includeStagesBeforeAsyncPoint 부울 includeStagesAfterAsyncPoint) 1,746
ImageButton2_ 클릭
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
어느 것이 16 번 라인입니까? – Oded
Dim 연결 As String = System.Configuration.ConfigurationManager.ConnectionStrings ("Database1"). ConnectionString() – user596379
응용 프로그램 구성에 "Database1"이라는 연결 문자열이 있습니까? – Oded