错误[42000] [Microsoft] [SQL Server Native Client 10.0] [SQL Server] BACKUP日志
问题描述:
hi
我正在使用sql server 2008.
hi
I'm using sql server 2008.
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
答
您必须按正确的顺序备份数据;即:
- 备份数据库
- 备份日志文件(如果数据库处于完全恢复模式)
- 收缩日志(只有它的大小是疯狂的;否则不必要)
缩小尚未清空的日志文件是没有意义的。也不需要关闭并重新打开每个命令的连接。
原理上,这可能是这样的: br />
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.
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()
在这里你可以找到一些关于SQL Server备份的基础知识:
创建完整数据库备份(SQL Server) [ ^ ]