App crashing and I dont know why

Posted on 2004-11-05
Last Modified: 2010-04-23
Ive been working on a sql app for a few weeks and its nearing completion, but during some final testing I stumbled on a bug that makes the app crash for no reason. Keep in mind that it works fine when the SQL server is running but when I stop it to check for error handling it returns the usual "Sql server does not exist or access is denied" but once I click OK it just closes additonal messages or anything. Here is the code that is called from a menu on an mdi form

// Begin

Private Sub CreateTable()

        Dim strSQL As String = _
            "IF EXISTS (" & _
            "SELECT * " & _
            "FROM master..sysdatabases " & _
            "WHERE Name = 'UserAudit')" & vbCrLf & _
            "DROP DATABASE UserAudit" & vbCrLf & _
            "CREATE DATABASE UserAudit"

        Dim frmStatusMessage As New frmStatus

        frmStatusMessage.MdiParent = Me.MdiParent
        frmStatusMessage.Show("Connecting to SQL Server")

            Dim SqlConnection As New SqlConnection(connectionstring)
            Dim cmd As New SqlCommand(strSQL, SqlConnection)


            msg = "Database 'UserAudit' successfully created!"
            style = MsgBoxStyle.DefaultButton1 Or _
            MsgBoxStyle.Information Or MsgBoxStyle.OKOnly
            title = "Database Creation"
            response = MsgBox(msg, style, title)

        Catch ex As Exception
            msg = ex.Message
            style = MsgBoxStyle.DefaultButton1 Or _
            MsgBoxStyle.Critical Or MsgBoxStyle.OKOnly
            title = "Connection Failed"
            response = MsgBox(msg, style, title)
        End Try
    End Sub

// End

Thanks for any help you guys can give.
Question by:JoeDW
    LVL 25

    Accepted Solution

    Hi this

                response = MsgBox(msg, style, title)
            End Try
        End Sub

    should be

                response = MsgBox(msg, style, title)
            End Try
        End Sub

    the seperate End will end your app
    LVL 1

    Author Comment

    Wow, I feel bad that I missed that one. Thanks alot because I completely overlooked that, it hadnt even dawned on me that it would be the cause.

    Thanks again for the help

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now