SHAN ABEYWICKRAMA – TECH BLOG

Microsoft Dynamics NAV | Business Central

C/AL

Get data from MySQL database using ODBC Connection

This topic shows you how to connect to MySQL database using ODBC Connection.

You may have to download the ODBC MySQL driver from MySQL Community downloads.

Download ODBC MySQL Connector
https://dev.mysql.com/downloads/connector/odbc/

You may also have to look up the required connection info that you have to provide. You can get connection string details with samples from this third-party site https://www.connectionstrings.com/

before  you start, it would better read and understand ODBC Connection.

ODBC Connection

https://docs.microsoft.com/en-us/dotnet/api/system.data.odbc.odbcconnection?view=dotnet-plat-ext-6.0

ODBC Command Type
https://docs.microsoft.com/en-us/dotnet/api/system.data.odbc.odbccommand.commandtype?view=dotnet-plat-ext-6.0

Make sure the driver you want is installed
  1.  Navigate to ODBC Data Sources (64-bit)
  2.  On the Drivers tab, you can find list of drivers
ODBC Data Source Administrator

 

Variables (DotNet Type)
OdbcConnection
System.Data.Odbc.OdbcConnection.’System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

Command
System.Data.Odbc.OdbcCommand.’System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

QueryReader
System.Data.Odbc.OdbcDataReader.’System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

Text Constants
ConnectionStr
DRIVER={MySQL ODBC 5.3 ANSI Driver}; Server=YourServerName/IP; PORT=MysqlPORT;Database=mysql; User=UserName; Password=PassWord; Option=1;

MySqlQuery
SELECT * FROM mysql.db

C/AL Code