How to load a .csv list?

How to load a .csv list?

Postby shamim429 » Mon 04 Jun 2007 20:03

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
shamim429
 
Posts: 3
Joined: Thu 12 Oct 2006 22:18
Location: New York, NY

Postby Alexey » Tue 05 Jun 2007 06:51

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.
Last edited by Alexey on Thu 07 Jun 2007 07:34, edited 1 time in total.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Where is libmysql.dll

Postby shamim429 » Wed 06 Jun 2007 12:46

Thank you for your help. Not sure where to get libmysql.dll, do I need to install mysql in every client PC?
shamim429
 
Posts: 3
Joined: Thu 12 Oct 2006 22:18
Location: New York, NY

Postby Alexey » Thu 07 Jun 2007 06:36

No, you don't need to. Just copy it to each machine.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for MySQL