Page 1 of 1

How to load a .csv list?

Posted: Mon 04 Jun 2007 20:03
by shamim429
Dear All,

I need to enable my client application users upload .csv files to a remote mysql server using VB.net. I was told to use "Direct=false" in connection string but it's giving me "libmysql.dll not found". Below is the code. Thanks in advance for any help.


Private Sub btnLoadList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadEmailList.Click

Try
Me.Cursor = Cursors.WaitCursor

'code to read .csv or .txt file (eg. _*.csv)
Dim openFile As New OpenFileDialog
openFile.Filter = "CSV File (*.csv) | *.csv|Text Files (*.txt)|*.TXT"
Dim myResult As DialogResult
myResult = openFile.ShowDialog

If openFile.FileName "" Then

'build LOAD DATA query
Dim SQL As String = "LOAD DATA INFILE '" & openFile.FileName & "' " & _
"INTO TABLE `email_blaster_database` " & _
"FIELDS TERMINATED BY '" & field_terminater.Text & "' " & _
"OPTIONALLY ENCLOSED BY '" & field_terminater.Text & "' " & _
"LINES TERMINATED BY '\r\n' " & _
" (title,first_name,mi,last_name,job_title,company_name,email)"

'MsgBox(SQL)


'new connection string
Dim myConnection_String As String = "host=remote.mysqlhost.com;" & _
"protocol=SSL;" & _
"Direct=false;" & _
"user=my_user;" & _
"Password='my_sql_passwd';" & _
"database=my_client_db"

'enable SSL & execute LOAD DATA Query.
Dim myConnection As MySqlConnection = New MySqlConnection(myConnection_String)
myConnection.SslOptions.CACert = "file://C:\ssl\cacert.pem"
myConnection.SslOptions.Cert = "file://C:\ssl\client-cert.pem"
myConnection.SslOptions.Key = "file://C:\ssl\client-key.pem"

Dim myCommand As New MySqlCommand(SQL, myConnection)
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

End If

Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Exclamation, " Line 5890")
Exit Try
Finally
Me.Cursor = Cursors.Default

End Try

End Sub

Posted: Tue 05 Jun 2007 06:51
by Alexey
You should put libmysql.dll to your application directory, system directory, to the path or any other place where LoadLibrary function is to search libraries.

Where is libmysql.dll

Posted: Wed 06 Jun 2007 12:46
by shamim429
Thank you for your help. Not sure where to get libmysql.dll, do I need to install mysql in every client PC?

Posted: Thu 07 Jun 2007 06:36
by Alexey
No, you don't need to. Just copy it to each machine.