Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Problema con Backup

Estas en el tema de Problema con Backup en el foro de Visual Basic clásico en Foros del Web. Estimados: he creado la siguiente forma para generar respaldos SQl de bases de datos (script sql) para mysql pero al hacer algunas pruebas me doy ...
  #1 (permalink)  
Antiguo 20/08/2007, 14:41
Avatar de ecerpa  
Fecha de Ingreso: mayo-2005
Mensajes: 61
Antigüedad: 19 años
Puntos: 1
Problema con Backup

Estimados:

he creado la siguiente forma para generar respaldos SQl de bases de datos (script sql) para mysql pero al hacer algunas pruebas me doy cuenta que los campos de la base de datos del tipo TETX no son guardados en el script

he investigado un monton y no logro averiguar lo que es...

adjunto el codigo por si me pueden guiar o ayudar de alguna forma

Cita:
Private Sub CreaRespaldos(ByVal strRuta As String, ByVal BaseDatos As String, _
ByVal server As String, _
Optional ByVal User As String, _
Optional ByVal Password As String)
Dim strConnString As String
Dim RecsetTablas As ADODB.Recordset
Dim RecsetCreateTable As ADODB.Recordset
Dim RecsetInsertInto As ADODB.Recordset
Dim Conn As ADODB.Connection

Dim strNombreTabla As String
Dim StrInsertInto As String
Dim NumFile As Long
Dim a As Long
Dim strSQL As String



On Error GoTo errh

Set Conn = New ADODB.Connection
'Abre la conexion con los parametros de entrada
strConnString = "Driver={mySQL ODBC 3.51 Driver};Server=" & _
server & ";Port=3306;Option=131072;Stmt=;Database=" & _
BaseDatos & ";Uid=" & User & ";Pwd=" & Password

Conn.Open strConnString


NumFile = FreeFile

LbStatus.Caption = "Inicializando..."

Open strRuta For Output As #NumFile
'Imprime encabezados informativos del archivo
Print #NumFile, "#Respaldo Automatico de la base " & BaseDatos
Print #NumFile, "#Fecha:" & Format(Date, "Short Date")
Print #NumFile, ""
Print #NumFile, "Use " & BaseDatos & ";"
Print #NumFile, ""

LbStatus.Caption = "Cargando Tablas..."

'Obtiene la lista de tablas
strSQL = UCase("SHOW TABLES FROM " & BaseDatos & ";")
Set RecsetTablas = Conn.Execute(strSQL)
With RecsetTablas
If Not .EOF Then
.MoveFirst

Do While Not .EOF
LbStatus.Caption = "Obteniendo estructura de la tabla " & strNombreTabla

strNombreTabla = .Fields(0).Value
'Obtiene la estructura de cada tabla en un recordset
strSQL = "SHOW CREATE TABLE `" & strNombreTabla & "`"
Set RecsetCreateTable = Conn.Execute(strSQL)

Print #NumFile, ""
Print #NumFile, "#"
Print #NumFile, "# Estructura de la tabla `" & strNombreTabla & "`"
Print #NumFile, "#"
Print #NumFile, ""

With RecsetCreateTable
'Imprime en el aerchivo cada campo y su definicion
If Not .EOF Then
.MoveFirst
Print #NumFile, .Fields(1).Value & ";"
Print #NumFile, ""
End If
End With
RecsetCreateTable.Close
Set RecsetCreateTable = Nothing

LbStatus.Caption = "Obteniendo Datos desde la tabla " & strNombreTabla

'Obtiene el contenido de la tabla
strSQL = "SELECT * FROM `" & strNombreTabla & "`;"

Set RecsetInsertInto = Conn.Execute(strSQL)

Print #NumFile, "#"
Print #NumFile, "# Datos de la tabla `" & strNombreTabla & "`"
Print #NumFile, "#"
Print #NumFile, ""

With RecsetInsertInto
If Not .EOF Then
.MoveFirst

Do While Not .EOF
LbStatus.Caption = .AbsolutePosition & " de " & .RecordCount & _
" Tabla: " & strNombreTabla

StrInsertInto = vbNullString
For a = 0 To .Fields.Count - 1
If Trim(StrInsertInto) <> vbNullString Then
'Formatea cada campo segun su tipo
If IsNull(.Fields(a).Value) Then
StrInsertInto = StrInsertInto & ", NULL"
Else
If .Fields(a).Type = adDBTimeStamp Or _
.Fields(a).Type = adDBDate Or _
.Fields(a).Type = adDate Then
StrInsertInto = StrInsertInto & ", " & _
Chr(34) & Format(.Fields(a).Value, _
"yyyy-mm-dd HH:mm:ss") & Chr(34)
Else
StrInsertInto = StrInsertInto & ", " & Chr(34) & _
.Fields(a).Value & Chr(34)
End If
End If
Else
If IsNull(.Fields(a).Value) Then
StrInsertInto = "NULL"
Else
If .Fields(a).Type = adDBTimeStamp Or _
.Fields(a).Type = adDBDate Or _
.Fields(a).Type = adDate Then
StrInsertInto = Chr(34) & _
Format(.Fields(a).Value, _
"yyyy-mm-dd HH:mm:ss") & Chr(34)
Else
StrInsertInto = Chr(34) & _
.Fields(a).Value & Chr(34)
End If
End If
End If
Next a
'Crea la cadena INSERt INTO, para ser exportada
StrInsertInto = "INSERT INTO `" & strNombreTabla & _
"` VALUES(" & StrInsertInto & ");"
Print #NumFile, StrInsertInto
.MoveNext
Loop
End If
.Close
End With
Set RecsetInsertInto = Nothing

.MoveNext
Loop
End If
.Close
End With
Set RecsetTablas = Nothing
LbStatus.Caption = "Proceso Terminado"

Close #NumFile
Conn.Close
Set Conn = Nothing
Comprimir (txtRuta.Text)
'MsgBox "Proceso de respaldo terminado, " & vbCr & _
" se creo el archivo " & strRuta
Exit Sub
errh:
If (Err.Number = -2147467259) Then
MsgBox "Servidor no encontrado", vbExclamation
Else
MsgBox "Error: " & Err.Number & " " & Err.Description
End If

End Sub
gracias por todo...
  #2 (permalink)  
Antiguo 20/08/2007, 18:53
Avatar de BrujoNic
Super Moderador
 
Fecha de Ingreso: noviembre-2001
Ubicación: Costa Rica/Nicaragua
Mensajes: 16.935
Antigüedad: 22 años, 5 meses
Puntos: 655
Re: Problema con Backup

Eso es programación.

Trasladado de BD a Visual Basic. Favor no poner código de programación en BD.

Función de la sección de Base de Datos
__________________
La tecnología está para ayudarnos. No comprendo el porqué con esa ayuda, la gente escribe TAN MAL.
NO PERDAMOS NUESTRO LINDO IDIOMA ESPAÑOL
  #3 (permalink)  
Antiguo 21/08/2007, 12:05
Avatar de okdoris  
Fecha de Ingreso: agosto-2007
Mensajes: 56
Antigüedad: 16 años, 8 meses
Puntos: 0
Re: Problema con Backup

pero el codigo es de visual, no cree que bale? ademas de seguro aca puede tener mas posibilidades de que encuentre una respuesta. Si usted sabe deberia colaborar, no cree?
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:33.