#StackBounty: #mysql #vb.net VB.Net MySQL Connector. Bulk insert stopped working

Bounty: 50

I’ve been using the code below to populate tables in a MySQL database for a few years and it’s been working fine.

Imports MySql.Data.MySqlClient

Public sub Thing(dt as datatable)

            Try
                'dt is datatable object populated from MSsqlServer
                Dim MySQLcmdSelect As MySqlCommand = New MySqlCommand("Select * From " & tableName) With {
                    .Connection = MySQLcnn
                }
                Dim MySQLad As New MySqlDataAdapter(MySQLcmdSelect)
                Dim MySQLcmdBuilder As New MySqlCommandBuilder(MySQLad)
                Dim MySQLcmd As MySqlCommand = MySQLcmdBuilder.GetInsertCommand()
                MySQLcmd.Connection = MySQLcnn
                MySQLad.InsertCommand = MySQLcmd
                MySQLad.Update(dt)
            Catch ex As Exception
                Debug.Print(ex.Message)
                Console.WriteLine("Error when populating " + tableName + ": " + ex.Message + vbCrLf + ex.InnerException.ToString)
                WriteLog(ex.Message)
            End Try
End Sub

The problem is, it’s stopped working!

The connector seems to be working ok as I can drop tables and create them, but this will not let me bulk insert the contents of the datatable ‘dt’ into the MySQL table.

It doesn’t throw an exception, it just passes over the .update(dt) line as if it were a Debug.Print() line when there’s 1000s of rows in dt.

Effectively I’m selectively extracting data from tables in MS SQLserver and bulk uploading them to tables with the same name in MySQL.

a) is this the best way to do it, and
b) why has this suddenly stopped working?

According to phpMyAdmin its Server version: 5.6.51 – MySQL Community Server (GPL)


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.