Visual Basic - ayuda con SQL

Life is soft - evento anual de software empresarial
 
Vista:

ayuda con SQL

Publicado por yeni (146 intervenciones) el 19/04/2006 04:10:17
Hola
Quisiera saber si me podrian ayudar... ya k quisiera saber como hacer mediante visual basic
realizar un Backup de una base de datos en SQL
.........
Gracias.. Besos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE: ayuda con SQL

Publicado por Low (102 intervenciones) el 19/04/2006 12:06:28
Prueba lo siguiente:

Con llamar a DB_Backup con los parametros correctos deberia servirte, suerte

'* * * * * * * * * * * * * *
'Passing Values
'* * * * * * * * * * * * * *
'nServer_Name = SQL server name
'nDB_Name = Database name
'nDB_Login = Login name
'nDB_Password = Password
'nBack_Dev =Backup device name
'nBack_Set = Backup set name
'nBack_Desc = Backup discription

'Backup device name has to be specified by the SQL ADMIN.
'Which comes under SQL Backup. The name you specified must
'be same as Passing value of backup device name.

'SQL ADMIN can only specify the device type(Tape, HD,...).

'* * * * * * * * * * * * * *

'* * * * * * * * * * * * * *

Option Explicit
Private oSQLServer As SQLDMO.SQLServer

Public Function DB_Backup(ByVal nServer_Name As String, _
ByVal nDB_Name As String, _
ByVal nDB_Login As String, ByVal nDB_Password As String, _
ByVal nBack_Dev As String, ByVal nBack_Set As String, _
ByVal nBack_Desc As String) As Boolean

' nServer_Name = SQL server name
' nDB_Name = Database name
' nDB_Login = Login name
' nDB_Password = Password
' nBack_Dev =Backup device name
' nBack_Set = Backup set name
' nBack_Desc = Backup discription
Dim oBackup As SQLDMO.Backup
Dim i As Integer
Dim swExist As Boolean
'On Error GoTo ErrorHandler
Set oBackup = CreateObject("SQLDMO.Backup")
If Connect_SQLDB(nServer_Name, nDB_Login, nDB_Password) Then
i = 1
Do
If oSQLServer.BackupDevices.Item(i).Name = nBack_Dev Then
swExist = True
End If
i = i + 1
Loop Until i > oSQLServer.BackupDevices.Count Or swExist = True

If Not swExist Then
Dim oDevice As New SQLDMO.BackupDevice
oDevice.Name = nBack_Dev
oDevice.Type = SQLDMODevice_DiskDump
oDevice.PhysicalLocation = IIf(Right(App.Path, 1) = "\", App.Path & nBack_Dev & ".bck", App.Path & "\" & nBack_Dev & ".bck")
oSQLServer.BackupDevices.Add oDevice
End If
oBackup.Devices = "[" & nBack_Dev & "]"
oBackup.Database = nDB_Name
oBackup.BackupSetName = nBack_Set
oBackup.BackupSetDescription = nBack_Desc
oBackup.SQLBackup oSQLServer
oSQLServer.DisConnect
DB_Backup = True
End If

Exit Function
ErrorHandler:
DB_Backup = False
End Function

Private Function Connect_SQLDB(ByVal nServer_Name As String, _
ByVal nDB_Login As String, _
ByVal nDB_Password As String) As Boolean

' nServer_Name = SQL server name
' nDB_Login = Login name
' nDB_Password = Password

Set oSQLServer = CreateObject("SQLDMO.SQLServer")
On Error GoTo ErrorHandler
Connect_SQLDB = False
oSQLServer.Connect nServer_Name, nDB_Login, nDB_Password
Connect_SQLDB = True
Exit Function
ErrorHandler:
oSQLServer.DisConnect
Connect_SQLDB = False
End Function
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar