Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-21
5
Medium Priority
?
1,040 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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

886 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