Solved

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

Posted on 2011-03-21
5
1,018 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP query / monitor data from Telnet to MySQL 8 128
MySql Recovery 2 42
Duplicated data in GROUP_CONCAT 2 52
Mysql query one to many 11 41
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.

751 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