library libmysql.dll
library libmysql.dll
hi. I try to build a basic program to connect to my database. I put this line in the program : #using "c:\Program Files\CoreLab\MySQLDirect.Net\CoreLab.MySQL.dll", but then i suppose you need to had a mysql library, otherwise you can't use Mysql command. i think you need the libmySQL.dll library. So my precise (and somewhat trivial ?) question is : how to "include" this library with VC++.net ? I tried several way, but it failed... thanks to answer me.
when using Db tools, i can connect to my data base, and make changes on it. But i can't do that with such simple program as this :
#include "stdafx.h"
#using
#using
#using
#using
#using
//c:\Program Files\CoreLab\MySQLDirect.Net\
using namespace System::Windows::Forms;
using namespace System;
using namespace System::Data;
using namespace System::Data::SqlClient;
// This is the entry point for this application
#ifdef _UNICODE
int wmain(void)
#else
int main(void)
#endif
{
// Create a SqlConnection object
// Set the connection string
MySqlConnection *cnPubs = new MySqlConnection("User=root; Host=localhost; Port=3306; Database=td";);
try
{
// Try to open the connection
cnPubs->Open();
Console::WriteLine(S"Connected to database successfully!");
}
catch (MySqlException * Xcp)
{
Console::Write(S"Error occurred: ");
Console::WriteLine(Xcp->Message);
}
// Close the connection
if (cnPubs->State != ConnectionState::Closed)
{
cnPubs->Close();
}
Console::WriteLine(S"The database connection is now closed");
because the compilator don't understand MySqlConnection and so on...
I could not find anywhere in the samples an example of such a simple application in C++.Net... would it be possible to send be a complete simple example so that i could at least connect to my database ?
#include "stdafx.h"
#using
#using
#using
#using
#using
//c:\Program Files\CoreLab\MySQLDirect.Net\
using namespace System::Windows::Forms;
using namespace System;
using namespace System::Data;
using namespace System::Data::SqlClient;
// This is the entry point for this application
#ifdef _UNICODE
int wmain(void)
#else
int main(void)
#endif
{
// Create a SqlConnection object
// Set the connection string
MySqlConnection *cnPubs = new MySqlConnection("User=root; Host=localhost; Port=3306; Database=td";);
try
{
// Try to open the connection
cnPubs->Open();
Console::WriteLine(S"Connected to database successfully!");
}
catch (MySqlException * Xcp)
{
Console::Write(S"Error occurred: ");
Console::WriteLine(Xcp->Message);
}
// Close the connection
if (cnPubs->State != ConnectionState::Closed)
{
cnPubs->Close();
}
Console::WriteLine(S"The database connection is now closed");
because the compilator don't understand MySqlConnection and so on...
I could not find anywhere in the samples an example of such a simple application in C++.Net... would it be possible to send be a complete simple example so that i could at least connect to my database ?
Re: library libmysql.dll
You forgot to enable CoreLab::MySql namespace.
Create Console Application (С++ .NET) project and try to add there the following code sample:
Create Console Application (С++ .NET) project and try to add there the following code sample:
Code: Select all
#include "stdafx.h"
#using
#using
using namespace System;
using namespace CoreLab::MySql;
int _tmain()
{
MySqlConnection * connection = new
MySqlConnection("User=root;Host=localhost;Port=3306;Database=test");
connection->Open();
Console::WriteLine( __box(connection->State)->ToString() );
connection->Close();
return 0;
}
pb of connection with mysql
ok, i think this is better with this line... But i have another problem : i use easyPHP, with Apache server. I change the port of this server from 80 to 8080. but when i try to connect to my data base using DbExplorer, it fails...whereas i could do that in the past. so there is still something wrong with the parameters....
well, maybe i made a mistake, now i'm ok with the coonection with DbExplorer. But, with your (somewhat changed) program :
#include "stdafx.h"
#using
#using
#using
#using
using namespace System;
using namespace System::Data;
using namespace CoreLab::MySql;
int main()
{
MySqlConnection * cntd= new MySqlConnection("User=root;Host=localhost;Port=3306;Database=td");
cntd->Open();
Console::WriteLine( __box(cntd->State)->ToString() );
cntd->Close();
return 0;
}
i have this error :
"C:\WINNT\SYSTEM32\NTDLL.DLL, Impossible to find or open a needed file DBG" , "C:\WINNT\SYSTEM32\SHELL32.DLL, Impossible to find or open a needed file DBG" and a lot of other similar error...
#include "stdafx.h"
#using
#using
#using
#using
using namespace System;
using namespace System::Data;
using namespace CoreLab::MySql;
int main()
{
MySqlConnection * cntd= new MySqlConnection("User=root;Host=localhost;Port=3306;Database=td");
cntd->Open();
Console::WriteLine( __box(cntd->State)->ToString() );
cntd->Close();
return 0;
}
i have this error :
"C:\WINNT\SYSTEM32\NTDLL.DLL, Impossible to find or open a needed file DBG" , "C:\WINNT\SYSTEM32\SHELL32.DLL, Impossible to find or open a needed file DBG" and a lot of other similar error...
Try instead of using this code:
to add in the project references using VisualStudio interface.
Code: Select all
#using
#using
#using
#using