Click here to Skip to main content
15,918,404 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi I'm using sql server 2008.

VB
con.Open()
           cmd = New OdbcCommand("DBCC SHRINKFILE(Legend_Log, 1)", con)
           cmd.ExecuteNonQuery()
           con.Close()
           con.Open()
           cmd = New OdbcCommand("BACKUP LOG Legend TO DISK=N'F:\full'", con)
           cmd.ExecuteNonQuery()
    i'm Getting below error on this line
       con.Close()
           con.Open()
           cmd = New OdbcCommand("DBCC SHRINKFILE(Legend, 1)", con)
           cmd.ExecuteNonQuery()
           con.Close()




ERROR [42000] [Microsoft][SQL Server Native Client 10.0][SQL Server]BACKUP LOG cannot be performed because there is no current database backup. ERROR [42000] [Microsoft][SQL Server Native Client 10.0][SQL Server]BACKUP LOG is terminating abnormally.


Help me to fix
Posted

1 solution

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:
VB
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)[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900