Desktop version

Main > Forum > 1C:Enterprise Platform > 1C:Integration > How can I read data from MySQL 5 database?

Forum

Search UsersRules
How can I read data from MySQL 5 database?
#1
Active user
Points:: 2
Joined:: Sep 16, 2011

I need to read and maybe write data from/to a database in MySQL 5 DBMS. Is it possible? And how can I do that?

Profile
#2
Active user
Points:: 0
Joined:: Sep 26, 2012

Yes, its possible. At first you need driver, and then

Code
ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;Port=3306;
|DATABASE=someDatabase;UID=user;PASSWORD=pass;
|OPTION=3;STMT=SET CHARACTER SET cp1251";
Connection     = New COMObject("ADODB.Connection");
Connection.Open(ConnectionString);

Command = New COMObject("ADODB.Command");
Command.ActiveConnection = Connection;
Command.CommandText = "select id fr om table";
Command.CommandType = 1;
       
RecordSet = New COMObject("ADODB.RecordSet");
RecordSet = Command.Execute();
While Not RecordSet.EOF Do
     Message(RecordSet.Fields("id").Value);
     RecordSet.MoveNext();
EndDo;

Profile
#3
Active user
Points:: 2
Joined:: Sep 16, 2011

I received the following error:

{ManagedApplicationModule(7)}: Error calling context method (Open)
Connection.Open(ConnectionString);
because:
An exception has occurred (Microsoft OLE DB Provider for ODBC Drivers): [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Profile
#4
Active user
Points:: 0
Joined:: Sep 26, 2012

check driver for proper installation
I use mysql-connector-odbc-5.2.2-win32.msi from mysql odbc driver

im not sure, but maybe win64 will approach too

and also remove text wrapping in connection string, I do it for nice view at forum

Profile
#5
Active user
Points:: 2
Joined:: Sep 16, 2011

It works!
I have downloaded and installed Connector/ODBC 5.2.2 Windows (x86, 32-bit), MSI Installer Connector-ODBC and changed the driver name to MySQL ODBC 5.2w Driver. By the way, the 64-bit version did not appeared in MS Excel when I tried to create a new data source to get a list of available ODBC connectors.
Thanks to Ivan!

P.S.:
It works fine even without of this line:

Code
RecordSet = New COMObject("ADODB.RecordSet");

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.