首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用SMO和VB.NET的SQL数据库备份

使用SMO和VB.NET的SQL数据库备份
EN

Stack Overflow用户
提问于 2012-03-25 06:41:46
回答 1查看 5.6K关注 0票数 0

我试图运行这段看似简单的代码,在网络上多次重复,但代码中出现了错误:

代码语言:javascript
复制
Imports System.Data.SqlClient
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common

Private Sub BackupDatabaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackupDatabaseToolStripMenuItem.Click
'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Reference the AdventureWorks2008R2 database.
Dim db As Database
db = srv.Databases("AdventureWorks2008R2")
'Store the current recovery model in a variable.
Dim recoverymod As Integer
recoverymod = db.DatabaseOptions.RecoveryModel
'Define a Backup object variable. 
Dim bk As New Backup
'Specify the type of backup, the description, the name, and the database to be backed up.
bk.Action = BackupActionType.Database
bk.BackupSetDescription = "Full backup of AdventureWorks2008R2"
bk.BackupSetName = "AdventureWorks2008R2 Backup"
bk.Database = "AdventureWorks2008R2"
'Declare a BackupDeviceItem by supplying the backup device file name in the constructor, and the type of device is a file.
Dim bdi As BackupDeviceItem
bdi = New BackupDeviceItem("Test_Full_Backup1", DeviceType.File)
'Add the device to the Backup object.
bk.Devices.Add(bdi)
'Set the Incremental property to False to specify that this is a full database backup.
bk.Incremental = False
'Set the expiration date.
Dim backupdate As New Date
backupdate = New Date(2006, 10, 5)
bk.ExpirationDate = backupdate
'Specify that the log must be truncated after the backup is complete.
bk.LogTruncation = BackupTruncateLogType.Truncate
'Run SqlBackup to perform the full database backup on the instance of SQL Server.
bk.SqlBackup(srv)
End Sub

我收到了以下几行的错误: Dim bk作为新备份

错误5类型“备份”未定义。

bk.Action = BackupActionType.Database

错误6 'BackupActionType‘未声明。由于其保护水平,它可能无法进入。

Dim bdi作为BackupDeviceItem

错误7类型'BackupDeviceItem‘没有定义。

以及其他类似的错误

我是不是错过了一些“进口品”?我从这里得到了代码:http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backup.sqlbackup.aspx

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-25 07:00:14

您需要添加对以下程序集的引用(而不仅仅是导入)

代码语言:javascript
复制
Microsoft.SqlServer.ConnectionInfo
Microsoft.SqlServer.Management.Sdk.Sfc
Microsoft.SqlServer.Smo
Microsoft.SqlServer.SmoExtended
Microsoft.SqlServer.SqlEnum
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9858380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档