分类: 数据库开发技术
2008-05-28 15:52:43
'得到SQL服务器的列表 '必须安装SQL SERVER 2000 SP2 及以上版本 Dim I As Short Dim sqlApp As New SQLDMO.Application() Dim ServerName As SQLDMO.NameList ServerName = sqlApp.ListAvailableSQLServers For i = 1 To ServerName.Count cbServer.Items.Add(ServerName.Item(i)) Next |
'得到指定SQL服务器所有数据库的列表 Dim sqlApp As New SQLDMO.Application() Dim oServer As New SQLDMO.SQLServer() oServer.Connect("(local)", "sa", "sa") cboDatabase.Items.Clear() Dim db As SQLDMO.Database For Each db In oServer.Databases Me.cboDatabase.Items.Add(db.Name) Next |
Dim I As Short Dim oServer As New SQLDMO.SQLServer() oServer.Connect("(local)", "sa", "sa") Dim db As New SQLDMO.Database() For I = 1 To oServer.Databases.Count If oServer.Databases.Item(I, "dbo").Name = "Northwind" Then Exit For Next If I > oServer.Databases.Count Then Exit Sub db = oServer.Databases.Item(I, "dbo") ListBox1.Items.Clear() '得到所有的存储过程 For I = 1 To db.StoredProcedures.Count ListBox1.Items.Add(db.StoredProcedures.Item(I, "dbo").Name) Next '得到所有的表 For I = 1 To db.Tables.Count ListBox1.Items.Add(db.Tables.Item(I, "dbo").Name) Next ' 得到所有的视图 For I = 1 To db.Views.Count ListBox1.Items.Add(db.Views.Item(I, "dbo").Name) Next |
'添加进度条ProgressBar1 '引用Microsoft SQLDMO Object Library '声明 Public WithEvents bkps As SQLDMO.Backup '数据库备份操作 Private Sub btnBackUp_Click(ByVal sender As .Object, ByVal e As System.EventArgs) Handles btnBackUp.Click Dim oSQLServer As New SQLDMO.SQLServer() oSQLServer.LoginSecure = False oSQLServer.Connect("(local)", "sa", "sa") '连接服务器 Me.Cursor = Windows.Forms.Cursors.WaitCursor bkps = CreateObject("SQLDMO.Backup") bkps.Database = "Northwind" '指定需备份的数据库 bkps.Action = 0 bkps.Files = "f:\Northwind.bak" '指定备份文件 bkps.Initialize = True ProgressBar1.Value = 0 ProgressBar1.Maximum = 100 Me.Cursor = Windows.Forms.Cursors.Default() Application.DoEvents() Dim mouseCur As Cursor Me.Cursor = Windows.Forms.Cursors.WaitCursor bkps.SQLBackup(oSQLServer) ProgressBar1.Value = 100 Application.DoEvents() bkps = Nothing Me.Cursor = Windows.Forms.Cursors.Default() MsgBox("数据库备份完成", MsgBoxStyle.Information, "系统消息") End Sub '显示进度 Private Sub bkps_PercentComplete(ByVal Message As , ByVal Percent As Integer) Handles bkps.PercentComplete ProgressBar1.Value = ProgressBar1.Maximum * (Percent / 100) End Sub |