简体   繁体   中英

How to fix ODBC Driver 8.0 SQL syntax error in SSIS?

I have a SSIS package which is used to export data from a MySQL database to a SQL database. For some reason, I can only read data using the ODBC Source item but I cannot preview the table, also, while doing some other tests I found out I can't insert data with the ODBC Destination item either.

Whenever I try I get this error:

ERROR [42000] [MySQL][ODBC 8.0(w) Driver][mysqld-5.7.23]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near " TABLENAME " at line 1 (myodbc8w.dll).

I'm using MySQL 5.7.23 and MySQL Connector/ODBC 8.0. I have tried switching between ANSI and Unicode connectors; downgrading the connectors version (tried it with 5.3, 5.2 and 5.1); changing database, table and column codification; changing the data access mode in the ODBC Source item (was using "Table Name" by default); remaking the task. Everything results in the same error, even on different computers and databases.

EDIT:

Using @Hadi second workaround lead to some interesting results (the first one didn't work for me).

Using either the ADO.NET or ODBC connector, the provided query resulted in an error.

Error Code: 1231. Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER'

After modifying the query to

set sql_mode = 'STRICT_TRANS_TABLES, NO_ENGINE_SUBSTITUTION, ANSI_QUOTES'

the error changed to a warning.

set sql_mode='STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES' 0 row(s) affected, 1 warning(s): 3135 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.

Still, it worked partially. Any quotations, accents, or any other symbol surrounding any selected table name had to be removed. That made it work fine when inserting data, but when retrieving data it had to be done either from a SQL command or by creating 2 different connections.

While searching for the issue i found some helpful links that mentioned some workaround:

(1) Connecting to MySQL issue

In this link the author mentioned 2 methods to connect to MySQL (using ODBC and ADO.net). He mentioned that while trying to retrieve tables using ODBC he received the same error that you have listed in the question, and he mentioned the solution as below:

Switching to use a SQL query instead, and that worked just fine. I was able to pull back both the correct metadata, with one small problem - the varchar(50) columns came back with a length of 51. This resulted in some warnings, but the package ran correctly.

(2) Writing to MySQL issue

In this article the author mentioned how to write to a MySQL destination using ADO.Net destination, he mentioned the solution below:

For the ADO.NET Destination to work properly, the MySQL database needs to have the ANSI_QUOTES SQL_MODE option enabled. This option can be enabled globally, or for a particular session. To enable it for a single session:

  1. Create an ADO.NET Connection Manager which uses the ODBC driver
  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.

Other similar links

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM