Solved

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Creating and Managing Databases with phpMyAdmin in cPanel.
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.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

743 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

11 Experts available now in Live!

Get 1:1 Help Now