Converting from HyperFileSqlDatabase to MS Acces database very slow!!

ProfessionalGold

New member
Joined
Dec 13, 2011
Messages
2
Programming Experience
Beginner
Hello,
Please help:
I am trying to convert HyperFileSqlDatabase to mdb database using this code:
****************************************
Code:
VB.NET:
Imports System.Data.OleDb
Imports System.Data.Odbc
Imports System.Text
Imports System.Data.SqlClient
Imports System.Data
Imports ADOX
Public Class Form1


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        Dim ADOXcatalog As New ADOX.Catalog
        Dim ADOXtable As New ADOX.Table


        If System.IO.File.Exists("d:\1.mdb") = True Then
            System.IO.File.Delete("d:\1.mdb")


        End If
        If System.IO.File.Exists("d:\1.ldb") = True Then
            System.IO.File.Delete("d:\1.ldb")


        End If
        If System.IO.File.Exists("d:\1.txt") = True Then
            System.IO.File.Delete("d:\1.txt")


        End If


        ADOXcatalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "d:\1.mdb")


        ADOXtable.Name = "Employees"
        ADOXtable.Columns.Append("ID", ADOX.DataTypeEnum.adInteger)
        ADOXtable.Columns.Append("Name", ADOX.DataTypeEnum.adLongVarWChar)
        ADOXtable.Columns.Append("Info1", ADOX.DataTypeEnum.adLongVarWChar)
        ADOXtable.Columns.Append("Info2", ADOX.DataTypeEnum.adLongVarWChar)
        ADOXtable.Columns.Append("Info3", ADOX.DataTypeEnum.adLongVarWChar)
        ADOXtable.Columns.Append("Info4", ADOX.DataTypeEnum.adLongVarWChar)
        ADOXtable.Columns.Append("Image", ADOX.DataTypeEnum.adLongVarWChar)     


        ADOXcatalog.Tables.Append(ADOXtable)
        ADOXtable = Nothing


        ADOXcatalog = Nothing


        Dim ConnectionStr1 As String = "Provider=PCSoft.HFSQL;Initial Catalog="D:\"
        Dim ConnectionStr2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "d:\1.mdb"
        Try
            Dim Connection1 As OleDbConnection = New OleDbConnection(ConnectionStr1)
            Dim Connection2 As OleDbConnection = New OleDbConnection(ConnectionStr2)
            Connection1.Open()
            Connection2.Open()
            Dim OleDbCmd1 As OleDbCommand = New OleDbCommand("SELECT * from Employees", Connection1)
            Dim OleDbRd1 As OleDbDataReader = OleDbCmd1.ExecuteReader
            
            Dim ByteImage() As Byte
            Dim Name, Info1, Info2, Info3, Info4,Image As String
            Dim ID As Integer


            'Dim i As Integer = 0


            While OleDbRd1.Read()
                ID = OleDbRd1(0)
                Name= OleDbRd1(1)
                Name= Name.Replace("'", "''")
                Info1= OleDbRd1(2)
                Info1= Info1.Replace("'", "''")
                Info2= OleDbRd1(3)
                Info2= Info2.Replace("'", "''")
                Info3= OleDbRd1(4)
                Info3= Info3.Replace("'", "''")
                ByteImage= OleDbRd1(5)
                Image = Encoding.ASCII.GetString(ByteImage)
                Image= Image.Replace("'", "''")
                
                Dim OleDbCmd2 As OleDbCommand = New OleDbCommand("INSERT INTO Employees(ID,Name,Info1,Info2,Info3,Image) VALUES (@ID,@Name,@Info1,@Info2,@Info3,Image)", Connection2)
                OleDbCmd2.Parameters.AddWithValue("@ID", ID)
                OleDbCmd2.Parameters.AddWithValue("@Name", Name)
                OleDbCmd2.Parameters.AddWithValue("@Info1", Info1)
                OleDbCmd2.Parameters.AddWithValue("@Info2", Info2)
                OleDbCmd2.Parameters.AddWithValue("@Info3", Info3)
                OleDbCmd2.Parameters.AddWithValue("@Q4", strQ4)
                OleDbCmd2.Parameters.AddWithValue("@Q5", strQ5)
                OleDbCmd2.Parameters.AddWithValue("@Image", Image)
               
                OleDbCmd2.ExecuteNonQuery()


                'i += 1
                'Dim ObjWriter As New System.IO.StreamWriter("D:\1.txt", True)
                'ObjWriter.WriteLine(i)
                'ObjWriter.Close()


                'Label1.Text = "file:" & i & " / 775"
                'Application.DoEvents()


            End While


            OleDbRd1.Close()
            OleDbCmd1.Dispose()
            Connection1.Close()
            Connection2.Close()
        Catch ex As OleDbException
            
            MsgBox(ex.ToString)
        End Try


        MsgBox("ok")
    End Sub  
End Class
**************************************
The problem is that the conversion is very slow.
Any suggestions please.
 
try code more like:

VB.NET:
Imports System.Data.OleDb
Imports System.Data.Odbc
Imports System.Text
Imports System.Data.SqlClient
Imports System.Data
Imports ADOX
Public Class Form1


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        Dim ADOXcatalog As New ADOX.Catalog
        Dim ADOXtable As New ADOX.Table


        If System.IO.File.Exists("d:\1.mdb") = True Then
            System.IO.File.Delete("d:\1.mdb")


        End If
        If System.IO.File.Exists("d:\1.ldb") = True Then
            System.IO.File.Delete("d:\1.ldb")


        End If
        If System.IO.File.Exists("d:\1.txt") = True Then
            System.IO.File.Delete("d:\1.txt")


        End If


        ADOXcatalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "d:\1.mdb")


        ADOXtable.Name = "Employees"
        ADOXtable.Columns.Append("ID", ADOX.DataTypeEnum.adInteger)
        ADOXtable.Columns.Append("Name", ADOX.DataTypeEnum.adLongVarWChar)
        ADOXtable.Columns.Append("Info1", ADOX.DataTypeEnum.adLongVarWChar)
        ADOXtable.Columns.Append("Info2", ADOX.DataTypeEnum.adLongVarWChar)
        ADOXtable.Columns.Append("Info3", ADOX.DataTypeEnum.adLongVarWChar)
        ADOXtable.Columns.Append("Info4", ADOX.DataTypeEnum.adLongVarWChar)
        ADOXtable.Columns.Append("Image", ADOX.DataTypeEnum.adLongVarWChar)     


        ADOXcatalog.Tables.Append(ADOXtable)
        ADOXtable = Nothing


        ADOXcatalog = Nothing


        Dim ConnectionStr1 As String = "Provider=PCSoft.HFSQL;Initial Catalog="D:\"
        Dim ConnectionStr2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "d:\1.mdb"
        Try
            Dim Connection1 As OleDbConnection = New OleDbConnection(ConnectionStr1)
            Dim Connection2 As OleDbConnection = New OleDbConnection(ConnectionStr2)
            Connection1.Open()
            Connection2.Open()
            Dim OleDbCmd1 As OleDbCommand = New OleDbCommand("SELECT * from Employees", Connection1)
            Dim OleDbRd1 As OleDbDataReader = OleDbCmd1.ExecuteReader
            
            Dim ByteImage() As Byte
            Dim Name, Info1, Info2, Info3, Info4,Image As String
            Dim ID As Integer


            'Dim i As Integer = 0

Dim OleDbCmd2 As OleDbCommand = New OleDbCommand("INSERT INTO Employees(ID,Name,Info1,Info2,Info3,Image) VALUES (@ID,@Name,@Info1,@Info2,@Info3,Image)", Connection2)
                OleDbCmd2.Parameters.AddWithValue("@ID", DUMMY)
                OleDbCmd2.Parameters.AddWithValue("@Name", DUMMY)
                OleDbCmd2.Parameters.AddWithValue("@Info1", DUMMY)
                OleDbCmd2.Parameters.AddWithValue("@Info2", DUMMY)
                OleDbCmd2.Parameters.AddWithValue("@Info3", DUMMY)
                OleDbCmd2.Parameters.AddWithValue("@Q4", DUMMY)
                OleDbCmd2.Parameters.AddWithValue("@Q5", DUMMY)
                OleDbCmd2.Parameters.AddWithValue("@Image", DUMMY)


            While OleDbRd1.Read()
                ID = OleDbRd1(0)
                Name= OleDbRd1(1)
                Name= Name.Replace("'", "''")
                Info1= OleDbRd1(2)
                Info1= Info1.Replace("'", "''")
                Info2= OleDbRd1(3)
                Info2= Info2.Replace("'", "''")
                Info3= OleDbRd1(4)
                Info3= Info3.Replace("'", "''")
                ByteImage= OleDbRd1(5)
                Image = Encoding.ASCII.GetString(ByteImage)
                Image= Image.Replace("'", "''")
                

                OleDbCmd2.Parameters("@ID") = ID
                OleDbCmd2.Parameters("@Name")= Name
                OleDbCmd2.Parameters("@Info1")=Info1
                OleDbCmd2.Parameters("@Info2")= Info2
                OleDbCmd2.Parameters("@Info3")= Info3
                OleDbCmd2.Parameters("@Q4")= strQ4
                OleDbCmd2.Parameters("@Q5")= strQ5
                OleDbCmd2.Parameters("@Image") = Image
               
                OleDbCmd2.ExecuteNonQuery()


                'i += 1
                'Dim ObjWriter As New System.IO.StreamWriter("D:\1.txt", True)
                'ObjWriter.WriteLine(i)
                'ObjWriter.Close()


                'Label1.Text = "file:" & i & " / 775"
                'Application.DoEvents()


            End While


            OleDbRd1.Close()
            OleDbCmd1.Dispose()
            Connection1.Close()
            Connection2.Close()
        Catch ex As OleDbException
            
            MsgBox(ex.ToString)
        End Try


        MsgBox("ok")
    End Sub  
End Class
no point makign a new command every loop, jsut reuse the old one and change the parameter values.. its the main appeal f parameterized queries as the db doesnt have to re-plan and compile the query every time. if it's still slow, do some measuring.. where is it slow?
 
Back
Top