The code below awaits two FolderItem: one is a Reference to the .sqlite file, the second is a Reference to the txt file to import data from (a \Tab is used as Field separator, an EndOfLine is for Records separation).
When the line () is run once, only two Records are imported to the data base until the crash, if I move it into the Loop, everything is imported correctly.
[code]Public Sub Import_Records(Import_SQL_FI As FolderItem, Import_TXT_FI As FolderItem)
// ====================================
//
// Name: Import_Records
// Params:
// Import_Txt_FI As FolderItem
// Import_SQL_FI As FolderItem
// Returns:
//
// ====================================
Var Import_TXT_TIS As TextInputStream
Var aLine As String
Import_TXT_TIS = TextInputStream.Open(Import_TXT_FI)
Import_TXT_TIS.Encoding = Encodings.UTF8
gRecords_db.DatabaseFile = mSQL.gRecords_FI
Try
gRecords_db.Connect
gRecords_db.ExecuteSQL(“BEGIN TRANSACTION”)
While Not Import_TXT_TIS.EOF
// Get a line
aLine = Import_TXT_TIS.ReadLine
// Insert a Line
gRecords_db.ExecuteSQL("INSERT INTO Records('Groupe', Title, 'Part_Number', Company, Released_On, Duration) VALUES "+_
"('" + NthField(aLine, Chr(9), 1) + "'," + _
" '" + NthField(aLine, Chr(9), 2) + "'," + _
" '" + NthField(aLine, Chr(9), 3) + "'," + _
" '" + NthField(aLine, Chr(9), 4) + "'," + _
" '" + NthField(aLine, Chr(9), 5) + "'," + _
" '" + NthField(aLine, Chr(9), 6) + "')")
// Display the data
wRecords.TF_Group_Name.Text = NthField(aLine, Chr(9), 1)
wRecords.TF_LP_Title.Text = NthField(aLine, Chr(9), 2)
wRecords.TF_Part_Number.Text = NthField(aLine, Chr(9), 3)
wRecords.TF_Company.Text = NthField(aLine, Chr(9), 4)
wRecords.TF_Released_On.Text = NthField(aLine, Chr(9), 5)
wRecords.TF_Duration.Text = NthField(aLine, Chr(9), 6)
wRecords.Invalidate
// Validate the added Record
gRecords_db.CommitTransaction // Crash here: Cannot commit: no transaction is active
Wend
Catch error As DatabaseException
MessageBox("Error: " + error.Message)
gRecords_db.RollbackTransaction
End Try
// Close the OS Reference to the .txt file
Import_TXT_TIS.Close
End Sub[/code]