Solved

How to configur Visual C++ 2010 with MYSQL using  DataReader with OLEDB

Posted on 2011-03-21
5
1,017 Views
Last Modified: 2012-05-11
Hi,
I am using Ado.Net with MYSQL and I can use DataTable to get information from the MYSQL DataBase.

I have installed the .Net connector from MYSQL and added references to
MySql.data
System
System.Data
in the project properties.

I am trying to use DataReader with System.Data.Oledb
When I run the attached code
In the line
myCon->Open();
I get the attached error. (see the attached file)
MySQLProv Provider is not registered on the local machine.

How can I solve it in order to use the DataReader.
Thanks
   
#include "stdAfx.h"
using namespace System;
using namespace System::Data;
using namespace MySql::Data::MySqlClient;
using namespace std;
//
#using <mscorlib.dll>
#include <tchar.h>
#using <system.dll>

#using <system.data.dll>

using namespace System::Data::OleDb;
#using <system.windows.forms.dll>
using namespace System::Windows::Forms;

int main()
{

//
OleDbConnection ^myCon = gcnew OleDbConnection("Provider=MySQLProv;Data Source=127.0.0.1,3307;User ID=root;Password=ttt");
		myCon->Open();
		
OleDbCommand ^myCmd = gcnew OleDbCommand("select idtable2 from table2", myCon);
OleDbDataReader ^m_Reader=myCmd->ExecuteReader();

OleDbDataReader ^m_Reader=myCmd->ExecuteReader();
Console::WriteLine(m_Reader->GetDateTime(0));
	}

Open in new window

error5.bmp
0
Comment
Question by:star90
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:lomo74
ID: 35188241
found this on the web:
http://forums.asp.net/t/1155049.aspx/1?The+MySQLProv+provider+is+not+registered+on+the+local+machine+

it seems you cannot use mysql net connector as an oledb provider.

also found this:
https://cherrycitysoftware.com/CCS/Home/default.aspx

hope it helps --
0
 

Author Comment

by:star90
ID: 35192769
Thanks for the answer.
Assuming I want to try using ODBC DataReader what do I need to change in the code above?

Do you have any example?
Thanks
0
 
LVL 8

Expert Comment

by:lomo74
ID: 35196845
try the following:
1) after installing ODBC drivers for mysql, go to ODBC administrator and create a datasource to your database
2) change the connection string to the following: DSN=your_datasource_name;UID=root;PWD=ttt
3) import namespace System::Data::Odbc and use OdbcXxxxxx objects instead of OleDb objects (eg OdbcConnection ^myCon = gcnew OdbcConnection("DSN=your_datasource_name;UID=root;PWD=ttt");
OdbcCommand ^myCmd = ....
and so on


0
 
LVL 8

Accepted Solution

by:
lomo74 earned 500 total points
ID: 35196904
or alternatively, you can skip the creation of the DSN and specify all settings into the connection string:

OdbcConnection ^myCon = gcnew OdbcConnection("Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;Port=3307;Database=yourdbname;Uid=root;Pwd=ttt");


0
 

Author Comment

by:star90
ID: 35199928
Thanks,
Its working!
OdbcConnection ^myCon = gcnew OdbcConnection("Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;Port=3307;Database=test;Uid=root;Pwd=ttt");
myCon->Open();
OdbcCommand ^myCmd = gcnew OdbcCommand("select idtable2 from table2", myCon);
OdbcDataReader ^m_Reader=myCmd->ExecuteReader();
while(m_Reader->Read())
{
Console::WriteLine(m_Reader->GetInt16(0));
}

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question