Problema: Devo fare il BACKUP dei dati contenuti nelle tabelle del Database, il tutto ripetuto per 4 PC dove risiede un Database mySQL ciascuno.
Il dettaglio: importante è che non devo fare il BACKUP totale, ma solamente il 95% dei dati contenuti nella tabella che poi io impostero la limitazione tramite la Query SQL con un WHERE !!!!
Il fine: creare in un quinto Database le tabelle presenti negli altri 4, per le tabelle con i nomi identici sommo i record nella tabella di destinazione, per le tabelle con nomi diversi le aggiungo al Database e inserisco i dati, in modo da avere un grande e unico Database che non e' altro che la somma dei 4 Database.
Dimensioni: 1 Database mySQL contiene 250 tabelle le quali contengono mediamente 500 record ciascuna suddivisi in 10 colonne, peso medio di 1 Database 10Mb.
Detto questo: io ho provato facendolo tramite dei cicli WHILE nidificati come da esempio.........
Codice:
Private Sub Estract_Insert()
oConnDB1.Open()
Dim schemaTable As DataTable = oConnDB1.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
Dim myArray(1000) As String
Dim i As Integer
For i = 0 To schemaTable.Rows.Count - 1
myArray(i) = schemaTable.Rows(i).Item(2).ToString
Next
oConnDB1.Close()
Dim TableName As String
Dim count As Integer
For count = 0 To myArray.Length Step 1
TableName = myArray(count)
'controlla che sia una tabella 'Utente'
If TableName.Substring(0, 5) = "logs_" Then
'crea la nuova tabella se non esiste già
Try
Dim oCommDB5 As New OleDbCommand("CREATE TABLE IF NOT EXISTS " & TableName & " ( " & _
"ID int(11)," & _
"Ora_Start_In datetime," & _
"Ora_End_In datetime," & _
"Ora_Start_Out datetime," & _
"Ora_End_Out datetime," & _
"CLI varchar(50)," & _
"Chiamato varchar(50)," & _
"Esito varchar(50)," & _
"Operator varchar(50))", oConnDB5)
oCommDB5.Connection.Open()
oCommDB5.ExecuteNonQuery()
oCommDB5.Connection.Close()
Catch
MessageBox.Show("Si è verificato un errore dirante la creazione della nuova tabella - " & TableName & "", "Errore!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
Exit Sub
End Try
'estrae i dati dalla tabella remota
Try
oConnDB1.Open()
Dim oComm As New OleDbCommand("SELECT * FROM " & TableName & " ORDER BY ID DESC", oConnDB1)
Dim oRead As OleDbDataReader = oComm.ExecuteReader
While oRead.Read
'inserisce i dati nella tabella locale
Try
Dim oComm1 As New OleDbCommand("INSERT INTO " & TableName & "(" & _
"ID," & _
"aaa," & _
"bbb," & _
"ccc," & _
"ddd," & _
"eee," & _
"fff," & _
"ggg," & _
"hhh" & _
") VALUES(" & _
"'" & oRead("ID") & "'," & _
"'" & oRead("aaa") & "'," & _
"'" & oRead("bbb") & "'," & _
"'" & oRead("ccc") & "'," & _
"'" & oRead("ddd") & "'," & _
"'" & oRead("eee") & "'," & _
"'" & oRead("fff") & "'," & _
"'" & oRead("ggg") & "'," & _
"'" & oRead("hhh") & "'" & _
")", oConnDB5)
oComm1.Connection.Open()
oComm1.ExecuteNonQuery()
oComm1.Connection.Close()
Catch
'MessageBox.Show("Si è verificato un errore dirante l'inserimento dei dati nella nuova tabella - " & TableName & "", "Errore!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
'Exit Sub
End Try
End While
oConnDB1.Close()
Catch
MessageBox.Show("Si è verificato un errore durante l'estrazione dei dati dalla tabella - " & TableName & "", "Errore!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
Exit Sub
End Try
End If
Next
End Sub
solamente che dopo che ha eseguito il tutto per 5/8 tabelle mi da un errore, non so se sono i driver MyOLEDB3 oppure il troppo peso da eseguire con cicli nidificati, oppure non so che altro dire ...........