locked
Stopping application RRS feed

  • Question

  • User928623293 posted

    Using Asp .Net Web forms VS 2015. Sql Server .mdf database. I have 5 day long career in Web programming.

    When I'm testing in the VS IDE, after I close the web page in the browse, I notice the application/Debugger is still running and I have to click the the stop button. Am I suppose to (or can I) stop the application when the browser tab closes.   Also, Is there some cleanup I should do because I'm starting to get Out of Memory Error.

    Tuesday, January 22, 2019 1:31 PM

All replies

  • User409696431 posted

    If you are debugging, yes, pressing the stop button will stop the application.

    If you are getting out of memory exceptions you have a bug of some kind.  We can't tell you what it is without seeing the code that causes it.

    Tuesday, January 22, 2019 4:03 PM
  • User928623293 posted

    Thanks for the reply,

    I understand that pressing the stop button in the IDE will stop the app.  But what I want to know is there some way that when I close the Web Page (click on the "X" on the tab) that it also stops the debugger.  Not use to having to manually stop the debugger.  I've been a VB programmer for years and when you close the app the debugger stops automatically.  I kept forgetting to press the stop button.

    As for the out of memory problem, here is my Web.config and my startup page,

    <?xml version="1.0"?>
    
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    
    <configuration>
        <system.web>
          <compilation debug="true" strict="false" explicit="true" targetFramework="4.5.2" />
          <httpRuntime executionTimeout="3600" maxRequestLength="1048576" targetFramework="4.5.2" />
          <machineKey validationKey="AutoGenerate,IsolateApps" decryptionKey="AutoGenerate,IsolateApps" decryption="Auto" />
        </system.web>
      <system.webServer >
        <security>
          <requestFiltering>
            <requestLimits maxAllowedContentLength="1073741824" />
          </requestFiltering>
        </security>
      </system.webServer>
      <connectionStrings>
        <add name="DBConnection" providerName="System.Data.SqlClient" connectionString= "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\AAWebsite\WebSite1\BooksDB.mdf;Integrated Security=True;Connect Timeout=30" />
      </connectionStrings>
    </configuration>
    Imports System
    Imports System.Collections.Generic
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Configuration
    Imports System.Data.SqlClient
    Imports System.Web.Configuration
    Imports System.Linq
    Imports System.Web
    Imports System.Data
    Imports System.IO
    Partial Class WebForm1
        Inherits System.Web.UI.Page
    
        Private Sub WebForm1_Load(sender As Object, e As EventArgs) Handles Me.Load
            If Not IsPostBack Then
                Me.lblMessage.Visible = False
                Me.HyperLink.Visible = False
    
                LoadImages()
            End If
        End Sub
    
        Private Sub LoadImages()
            Dim cs As String = ConfigurationManager.ConnectionStrings("DBConnection").ConnectionString
            Using con As New SqlConnection(cs)
                con.Open()
                Using cmd As New SqlCommand("Select * from tblImages", con)
                    Dim rdr As SqlDataReader = cmd.ExecuteReader
                    Me.GridView1.DataSource = rdr
                    Me.GridView1.DataBind()
                End Using
            End Using
        End Sub
    
        Protected Sub btnUpload_Click(sender As Object, e As EventArgs) Handles btnUpload.Click
            Dim postedFile As HttpPostedFile = Me.FileUpload1.PostedFile
            Dim fileName As String = Path.GetFileName(postedFile.FileName)
            Dim fileExtention As String = Path.GetExtension(fileName)
            Dim fileSize As Integer = postedFile.ContentLength
    
            If (fileExtention.ToLower = ".jpg" Or fileExtention.ToLower = ".bmp" Or
                fileExtention.ToLower = ".gif" Or fileExtention.ToLower = ".png") Then
    
                Dim stream As Stream = postedFile.InputStream
                Dim binaryReader As BinaryReader = New BinaryReader(stream)
                Dim bytes As Byte() = binaryReader.ReadBytes(CInt(stream.Length))
    
                Dim cs As String = ConfigurationManager.ConnectionStrings("DBConnection").ConnectionString
                Using con As New SqlConnection(cs)
                    con.Open()
                    'Using cmd As New SqlCommand("Insert into tblImages (Name, Size, ImageData) Values (@Name, @Size, @ImageData); Select scope_identity()", con)
                    Using cmd As New SqlCommand("spUpLoadImage", con)
                        cmd.CommandType = CommandType.StoredProcedure
                        cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = CType(fileName, String)
                        cmd.Parameters.Add("@Size", SqlDbType.Int).Value = CType(fileSize, Integer)
    
                        cmd.Parameters.Add("@ImageData", SqlDbType.VarBinary).Value = CType(bytes, Byte())
    
                        cmd.Parameters.Add("@NewId", SqlDbType.Int).Value = -1
                        cmd.Parameters("@NewId").Direction = ParameterDirection.Output
    
                        cmd.ExecuteNonQuery()
                        
                        Me.lblMessage.Visible = True
                        Me.lblMessage.Text = "Image File Added  ID = " & cmd.Parameters("@NewId").Value.ToString
                        Me.lblMessage.ForeColor = System.Drawing.Color.Green
                        HyperLink.Visible = True
                        HyperLink.NavigateUrl = "~/WebForm2.aspx?Id=" & cmd.Parameters("@NewId").Value.ToString
    
                        'LoadImages()
                    End Using
                End Using
    
            Else
                Me.lblMessage.Visible = True
                Me.lblMessage.Text = "Error, Not an Image File"
                Me.lblMessage.ForeColor = System.Drawing.Color.Red
                HyperLink.Visible = False
            End If
        End Sub
    End Class
    
    
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="WebForm1.aspx.vb" Inherits="WebForm1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
        </div>
            <asp:FileUpload ID="FileUpload1" runat="server" />
            <p>
            <asp:Button ID="btnUpload" runat="server" Text="Upload" style="; top: 0px; left: 0px; height: 33px" />
            </p>
            <p>
            <asp:Label ID="lblMessage" runat="server" Text="Label" style=""></asp:Label>
            </p>
            <p>
            <asp:HyperLink ID="HyperLink" runat="server" style="">View Uploaded Image</asp:HyperLink>
            </p>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" style="; top: -75px; left: 339px" >
                <Columns>
                    <asp:BoundField DataField="Id" HeaderText="Id" />
                    <asp:BoundField DataField="Name" HeaderText="Name" />
                    <asp:BoundField DataField="Size" HeaderText="Size (bytes)" />
                    <asp:TemplateField HeaderText="Image" >
                        <ItemTemplate>
                            <asp:Image ID="Image1" runat="server" height="100px" Width="140px"
                                imageurl='<%#"data:Image/png;base64," & Convert.ToBase64String(CType(Eval("ImageData"), Byte())) %>' />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </form>
    </body>
    </html>

    Tuesday, January 22, 2019 6:24 PM
  • User409696431 posted

    " But what I want to know is there some way that when I close the Web Page (click on the "X" on the tab) that it also stops the debugger."

    How it behaves is how it behaves.  You can't change that.  It's not hard to get used to pressing the stop button.

    Tuesday, January 22, 2019 10:54 PM
  • User928623293 posted

    Yeah, it's not a matter of it being hard, just after so many years of VB programming where when you close the app the debugger stops too, it just doesn't come natural.  Was hoping there was some setting or command.  But if that's the way it is then I'll just have to get use to it.  

    Thanks for the reply.

    Wednesday, January 23, 2019 1:30 AM
  • User-893317190 posted

    Hi wes4dbt@sbcglobal.net,

    As far as I know, closing the tab of your debugging page doesn't always stop the application.

    What causes the application to stop is  closing the whole browser.

    If you  have opened a new page(even a blank page) when you debug,  when you close your debugging page,the application will not stop.

    You should close the browser where you open your debugging page.

    Best regards,

    Ackerly Xu

    Wednesday, January 23, 2019 4:24 AM