This is a puzzling one.
I am writing a sql server backup routine in vb.net sending an sql command of the form
USE fred;
BACKUP DATABASE fred TO DISK = 'c:\fred.bak'
WITH FORMAT,
MEDIANAME = 'Z_SQLServerBackups',
NAME = 'Full Backup of fred on 19 Jun 2009 at 09:42:51'
and it generally works ok - i've got a try catch clause around the execute command and if the database doesnt exist (for instance) the err.description gives
Could not locate entry in sysdatabases for database 'fred'. No entry found with that name. Make sure that the name is entered correctly.
However if i try to dump the database to another server doing it manually on server management studio fails giving the message
Msg 3201, Level 16, State 1, Line 2
Cannot open backup device '\\JBA01\DBBackup\PO19jun2009v2.Bak'. Operating system error 1326(Logon failure: unknown user name or bad password.).
Msg 3013, Level 16, State 1, Line 2
BACKUP DATABASE is terminating abnormally.
but running the vb.net code the try catch doesnt detect it as a failure - is there some kind of exception i'm not trapping? Code included below
I am writing a sql server backup routine in vb.net sending an sql command of the form
USE fred;
BACKUP DATABASE fred TO DISK = 'c:\fred.bak'
WITH FORMAT,
MEDIANAME = 'Z_SQLServerBackups',
NAME = 'Full Backup of fred on 19 Jun 2009 at 09:42:51'
and it generally works ok - i've got a try catch clause around the execute command and if the database doesnt exist (for instance) the err.description gives
Could not locate entry in sysdatabases for database 'fred'. No entry found with that name. Make sure that the name is entered correctly.
However if i try to dump the database to another server doing it manually on server management studio fails giving the message
Msg 3201, Level 16, State 1, Line 2
Cannot open backup device '\\JBA01\DBBackup\PO19jun2009v2.Bak'. Operating system error 1326(Logon failure: unknown user name or bad password.).
Msg 3013, Level 16, State 1, Line 2
BACKUP DATABASE is terminating abnormally.
but running the vb.net code the try catch doesnt detect it as a failure - is there some kind of exception i'm not trapping? Code included below
Code:
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim MyCmd = New ADODB.Command
' Dim cmd As New ADODB.Command
Try
' make the connection
cn.Open(strConn)
' set the command
MyCmd.CommandText = strSQL
MyCmd.CommandType = ADODB.CommandTypeEnum.adCmdText
MyCmd.ActiveConnection = cn
' set the timeout
If intTimeoutPeriod <> -1 Then
cn.CommandTimeout = intTimeoutPeriod
End If
' run the command to dump the database
MyCmd.Execute()
Catch
' output a less than cheery message
strerror = "!!! Database dumped failed - source " & strDatabaseName & _
" dumping to " & strFolderName & strwork & " - error " & Err.Description & " !!!" & vbLf
Console.Write(strerror)
funcAddToEmailMessage(strerror, constFailureMessage)
Exit Sub
End Try