Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to load bulk records of text files in my database using VB.NET and I run into a fatal error.
HERE'S MY CODE:

VB
Public Sub LoadStudent(ByVal filepath As String)

Dim sql As String

sql =  "load data infile local '" & filepath & "' into table student_academic_table fields terminated by '\t' lines terminated by '\r\n' (@col1, @col2, @col3, @col4, @col5, @col6, @col7, @col8, @col9, @col10, @col11, @col12, @col13) set StudentIDNumber = @col1, LastName = @col2, FirstName = @col3, MiddleName = @col4, Course = @col5, _Year = @col6, Gender = @col7, OfferCode = @col8, SubjectName = @col9, SubjectDescription = @col10, MidtermGrade = @col11, FinalGrade = @col12, Units = @col13, TermCode = 0;"


SC.LoadData(sql)

End Sub

Here's the code for SC.LoadData(sql):

Public Function LoadData(ByVal sql As String) As Long

VB
If sql.Trim.ToLower.StartsWith("load") Then
           Try
               Connect()
               cmd.CommandText = sql
               cmd.Connection = con
               Return cmd.ExecuteNonQuery()
               Disconnect()
           Catch ex As MySqlException
               Console.Write(ex.Message)
               MessageBox.Show(ex.Message)
           End Try
       End If
       Return 0

   End Function


I made it as a sub so that I can use it to other functions, but it doesn't carry on the desired function that I want it to do, instead it throws a fatal error exception in the database. I tried executing it directly in my MySql Query Browser and it executed. But in my VB.NET application it fires a fatal error, I've already looked up in google and other forums for related articles or topics but I couldn't find any answer. My guess its version compatibility and I have no idea how to fix these kind of problems. PLEASE HELP.
Posted
Updated 18-Feb-15 18:13pm
v2

1 solution

Without seeing all of the relevant code and the error details, I'd say that you have a potential problem in the filepath variable.

For example if you select a file from your C-drive and pass the file name along with path and the database is located on a separate computer, it doesn't see the file in the path you have specified. Even if it resides on the same computer, does the database have access to the directory you have specified.
 
Share this answer
 
Comments
ChuckieMacasero 19-Feb-15 0:31am    
Thank you for the answer, I tried changing the rights of the file I am trying to load and it still fires the same error, Im running MySql in my computer Im using a localhost. And why is it that if I try to execute it in my MySql Query Browser it executes but in my VB application it throw error? Is this concerns with the length of the query?
Wendelius 19-Feb-15 0:35am    
The length of the query is not likely the reason. What is the full error you get?

Also using debugger, copy the statement that is going to be executed in your code to the clipboard and try to run that in MySql. Does it run? This way you can ensure that the statement is exactly the same in both cases.
ChuckieMacasero 19-Feb-15 0:53am    
It only says fatal error encountered during command execution.

here the query that it executes that I copied on the clip board:

load data infile 'C:/Users/SHYNX/Desktop/sample.txt' into table student_academic_table fields terminated by '\t' lines terminated by '\r\n' (@col1, @col2, @col3, @col4, @col5, @col6, @col7, @col8, @col9, @col10, @col11, @col12, @col13) set StudentIDNumber = @col1, LastName = @col2, FirstName = @col3, MiddleName = @col4, Course = @col5, _Year = @col6, Gender = @col7, OfferCode = @col8, SubjectName = @col9, SubjectDescription = @col10, MidtermGrade = @col11, FinalGrade = @col12, Units = @col13, TermCode = 3;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900