用sqldmo可实现对sqlserver的备份,但无进度条。用VB就可以。请看源码。
VB的源码:
关键在于oBackupEvent ,我想问一下
oBackupEvent 是oBackUp的一个事件吗?Dim gSQLServer As SQLDMO.SQLServer
Dim WithEvents oBackupEvent As SQLDMO.Backup On Error GoTo ErrHandler:
Dim oBackup As SQLDMO.Backup
gDatabaseName = cmbDatabaseName.Text
Set oBackup = New SQLDMO.Backup
Set oBackupEvent = oBackup ' enable events
oBackup.Database = gDatabaseName
gBkupRstrFileName = txtDataFileName.Text
oBackup.Files = gBkupRstrFileName
' Delete the datafile to allow the application to create a brand new file.
' This will prevent attaching the new backup data to the old data if there
' is any.
If Len(Dir(gBkupRstrFileName)) > 0 Then
Kill (gBkupRstrFileName)
End If
' Change mousepointer while trying to connect.
Screen.MousePointer = vbHourglass
' Backup the database.
oBackup.SQLBackup gSQLServer
' Change mousepointer back to the default after connect.
Screen.MousePointer = vbDefault
Set oBackupEvent = Nothing ' disable events
Set oBackup = Nothing
Exit SubPrivate Sub oBackupEvent_PercentComplete(ByVal Message As String, ByVal Percent As Long)
PrintStat "oBackupEvent_PercentComplete -- " & Message & " " & Percent
End Sub而对应的Delphi代码如下:
gSQLServer := CreateOleObject('SQLDMO.SQLServer');
oBackUp := CreateOleObject('SQLDMO.BackUp'); gSQLServer.LoginSecure := false;
gSQLServer.LoginTimeout := 15;
gSQLServer.Connect('angel', 'sa', 'zonekingsa');
oBackUp.Files := 'c:\Northwind.bak';
oBackUp.DataBase := 'Northwind';
oBackUp.SQLBackUp(gSQLServer);
ShowMessage('success'); gSQLServer := Unassigned;
oBackUp := Unassigned;最关键的地方在于给oBackUp这个对象加上CompletePercent这个事件。
但我如何也加不上,哪位大侠做过,请指点一二。。
VB的源码:
关键在于oBackupEvent ,我想问一下
oBackupEvent 是oBackUp的一个事件吗?Dim gSQLServer As SQLDMO.SQLServer
Dim WithEvents oBackupEvent As SQLDMO.Backup On Error GoTo ErrHandler:
Dim oBackup As SQLDMO.Backup
gDatabaseName = cmbDatabaseName.Text
Set oBackup = New SQLDMO.Backup
Set oBackupEvent = oBackup ' enable events
oBackup.Database = gDatabaseName
gBkupRstrFileName = txtDataFileName.Text
oBackup.Files = gBkupRstrFileName
' Delete the datafile to allow the application to create a brand new file.
' This will prevent attaching the new backup data to the old data if there
' is any.
If Len(Dir(gBkupRstrFileName)) > 0 Then
Kill (gBkupRstrFileName)
End If
' Change mousepointer while trying to connect.
Screen.MousePointer = vbHourglass
' Backup the database.
oBackup.SQLBackup gSQLServer
' Change mousepointer back to the default after connect.
Screen.MousePointer = vbDefault
Set oBackupEvent = Nothing ' disable events
Set oBackup = Nothing
Exit SubPrivate Sub oBackupEvent_PercentComplete(ByVal Message As String, ByVal Percent As Long)
PrintStat "oBackupEvent_PercentComplete -- " & Message & " " & Percent
End Sub而对应的Delphi代码如下:
gSQLServer := CreateOleObject('SQLDMO.SQLServer');
oBackUp := CreateOleObject('SQLDMO.BackUp'); gSQLServer.LoginSecure := false;
gSQLServer.LoginTimeout := 15;
gSQLServer.Connect('angel', 'sa', 'zonekingsa');
oBackUp.Files := 'c:\Northwind.bak';
oBackUp.DataBase := 'Northwind';
oBackUp.SQLBackUp(gSQLServer);
ShowMessage('success'); gSQLServer := Unassigned;
oBackUp := Unassigned;最关键的地方在于给oBackUp这个对象加上CompletePercent这个事件。
但我如何也加不上,哪位大侠做过,请指点一二。。
解决方案 »
- 各位新年好!请问:向Memo1添加多行内容后如何使光标移回第一行的位置上?
- 如何用delphi 编写获取路由器的 动态ip地址
- pas调用dll里的函数比调用该pas里面的函数时间长吗?
- 还是论坛关闭前的问题,400分求两本书!!!
- 请教高手
- 高分題﹗﹗
- 多表联合统计!诚征高手解答。
- 如何强制控制DBGrid中字段的长度
- 句柄是什么意思???
- VB中的RecordSet和Delphi中的TAdoDataSet什么的控件是否兼容
- 我用CreateOleObject引用了一个Aotomation对象,但我如何引用它的事件呢?
- 请问怎么样,读取的SQL中的binary到TmemorySTream.先谢了
谢谢我已经先做好一个假的,先应付过关,呵呵。。真的慢慢研究中。。
http://expert.csdn.net/Expert/TopicView1.asp?id=1905529
应该是一个回调函数,你可以在delphi中申明同样各式的全局函数,然后将地址付给对象。-----
我没有试,你可以试一下