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("Con necting to SQL Server")
Try
Dim SqlConnection As New SqlConnection(connectionst ring)
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
// 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
frmStatusMessage.Show("Con
Try
Dim SqlConnection As New SqlConnection(connectionst
Dim cmd As New SqlCommand(strSQL, SqlConnection)
SqlConnection.Open()
frmStatusMessage.Close()
cmd.ExecuteNonQuery()
SqlConnection.Close()
msg = "Database 'UserAudit' successfully created!"
style = MsgBoxStyle.DefaultButton1
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again for the help