Link to home
Start Free TrialLog in
Avatar of JoeDW
JoeDW

asked on

App crashing and I dont know why

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 out...no 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")

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

            SqlConnection.Open()
            frmStatusMessage.Close()
            cmd.ExecuteNonQuery()
            SqlConnection.Close()

            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
            frmStatusMessage.Close()
            msg = ex.Message
            style = MsgBoxStyle.DefaultButton1 Or _
            MsgBoxStyle.Critical Or MsgBoxStyle.OKOnly
            title = "Connection Failed"
            response = MsgBox(msg, style, title)
            End
        End Try
    End Sub

// End


Thanks for any help you guys can give.
Joe
ASKER CERTIFIED SOLUTION
Avatar of RonaldBiemans
RonaldBiemans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JoeDW
JoeDW

ASKER

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