You have to backup your data in the right order; that is:
- Backup the database
- Backup the log file (if the database is in full recovery mode)
- Shrink the log (only if its size is insane; unnecessary otherwise)
There is no sense in shrinking a log file that has not been emptied yet. No need to close and reopen a connection at each command, too.
[EDIT]
Schematically, that could be something like:
Dim result As Integer
con.Open()
cmd = New OdbcCommand("BACKUP DATABASE Legend TO DISK=N'F:\full'", con)
result = cmd.ExecuteNonQuery()
cmd.CommandText = "BACKUP LOG Legend_log TO DISK=N'F:\full'"
result = cmd.ExecuteNonQuery()
cmd.CommandText = "DBCC SHRINKFILE(Legend_log, 1)"
result = cmd.ExecuteNonQuery()
con.Close()
Here you can find some very basics about SQL Server backups:
Create a Full Database Backup (SQL Server)[
^]