Solved

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

Posted on 2011-03-21
5
1,011 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now