Blog Post

SQL Server Integration Services (SSIS) Blog
2 MIN READ

Writing to a MySQL database from SSIS

SSIS-Team's avatar
SSIS-Team
Copper Contributor
Mar 25, 2019
First published on MSDN on Jan 07, 2009

A couple of users reported being unable to use the ADO.NET destination to insert data into their mysql databases. When I http://blogs.msdn.com/mattm/archive/2008/03/03/connecting-to-mysql-from-ssis.aspx , it worked, but it seems like changes made since the early 2008 CTPs have made us incompatible with MySQL. We do have a bug logged to make this more flexible, but the good news is that in the meantime there is a workaround when using the http://dev.mysql.com/downloads/connector/odbc/5.1.html .

For the ADO.NET Destination to work properly, the MySQL database needs to have the http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_ansi_quotes http://dev.mysql.com/doc/refman/5.0/en/faqs-sql-modes.html option enabled. This option can be http://dev.mysql.com/doc/refman/5.0/en/faqs-sql-modes.html#qandaitem-23-3-4 , or for a particular session. To enable it for a single session:

  1. Create an ADO.NET Connection Manager http://blogs.msdn.com/mattm/archive/2008/03/03/connecting-to-mysql-from-ssis.aspx
  2. Set the connection manager’s RetainSameConnection property to True
  3. Add an Execute SQL Task before your data flow to set the SQL_MODE – Ex. set sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION ,ANSI_QUOTES '
  4. Make sure that your Execute SQL Task and your ADO.NET Destination are using the same connection manager.

Setting the RetainSameConnection property to True will ensure that your Execute SQL Task and ADO.NET Destination are in the same session.

Note, I recommend using the ODBC Driver when writing to the MySQL database, because the http://dev.mysql.com/downloads/connector/net/5.2.html has an additional blocking issue. If you try it out, you’ll get an error which looks something like this:

Error: 2009-01-05 12:03:47.79
Code: 0xC020844B
Source: Data Flow Task 1 Destination - Query [28]
Description: An exception has occurred during data insertion, the message returned from the provider is: You have an
error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use nea
r '"name", "date", "type", "remark") VALUES (p1, p2, p3, p4), (p1,p2,p3,p4), (p1,p2' at line 1
End Error

Note that the “VALUES” portion has parameter names, and not the actual values. This appears to be an issue with the value the MySQL provider returns for its ParameterMarkerFormat. I did find a http://bugs.mysql.com/bug.php?id=25950 , but it looks like they decided not to fix it. I’ve heard that the http://devart.com/dotconnect/mysql/ do not have this problem, but I haven’t been able to try them out myself.

Updated Mar 25, 2019
Version 2.0