Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/08/2007, 14:41
Avatar de ecerpa
ecerpa
 
Fecha de Ingreso: mayo-2005
Mensajes: 61
Antigüedad: 19 años, 11 meses
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...