Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 对象引用未设置为对象的实例_Vb.net_Iis - Fatal编程技术网

Vb.net 对象引用未设置为对象的实例

Vb.net 对象引用未设置为对象的实例,vb.net,iis,Vb.net,Iis,我不知道在服务器上部署web时为什么会出现此错误。是因为我的连接字符串有问题吗?请帮帮我。谢谢你 Web.config <add name="Database1" connectionString="Data Source='170.21.191.85';Initial Catalog='Database1';User ID='sa';Password='123'"/> 堆栈跟踪 [NullReferenceException:对象引用未设置为对象的实例。] WebApplica

我不知道在服务器上部署web时为什么会出现此错误。是因为我的连接字符串有问题吗?请帮帮我。谢谢你

Web.config

 <add name="Database1" connectionString="Data Source='170.21.191.85';Initial Catalog='Database1';User ID='sa';Password='123'"/>
堆栈跟踪

[NullReferenceException:对象引用未设置为对象的实例。] WebApplication1.Login.ImageButton2\u在C:\Users\L30810\Desktop\fyp final.14\WebApplication1\Login.aspx.vb:16中单击(对象发送者,ImageClickEventArgs e) System.Web.UI.WebControl.ImageButton.OnClick(ImageClickEventArgs e)+86 System.Web.UI.WebControl.ImageButton.RaisePostBackEvent(String eventArgument)+115 System.Web.UI.WebControl.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(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)+1746

图像按钮2\u单击

 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

您不需要引用连接字符串中的值

<add name="Database1" connectionString="Data Source=170.21.191.85;Initial Catalog=Database1;User ID=sa;Password=final"/>


@user596379-代码?我在哪里说的代码?我说引用。您不需要在连接字符串中使用
。您应该使用
User ID=sa,而不是
用户ID='sa'.oops对不起..我错了。我要试一试。@user596379-它发生在哪一行?堆栈跟踪是什么?您可以编辑您的问题并将这些详细信息添加到其中吗?@user596379-您是否从连接字符串的所有值中删除了单引号,如我的示例所示?您可以发布
ImageButton2\u单击
的内容吗?将连接设置为String=System.Configuration.ConfigurationManager.ConnectionStrings(“Database1”)。ConnectionString()您确定应用程序配置具有名为“Database1”的连接字符串吗?这实际上是在
配置部分?我把它放在configSections标签中时出错。元素“configSections”具有无效的子元素“ConnectionString”。可能元素的列表应为“节,节组”。可能重复的
<add name="Database1" connectionString="Data Source=170.21.191.85;Initial Catalog=Database1;User ID=sa;Password=final"/>