I got a problem when using mysql connector with wxWidgets my program crashes right when I start debugging, but it gives no compiler errors.

Main.h

#ifndef __MAIN_H
#define __MAIN_H
#include <wx/frame.h>
#include <wx/textctrl.h>
#include <wx/button.h>

// Mysql

#include "mysql_connection.h"

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>

class MainApp: public wxApp
{
public:
	virtual bool OnInit();
};

class MainFrame: public wxFrame
{
public:

	// Kaikki PUBLIC ARVOIKSI!

	MainFrame( const wxString & title, const wxPoint & pos, const wxSize & size );

	void Exit(wxCommandEvent & event);
	void ChangeLanguage(wxCommandEvent & event);
	void Checklogin(wxCommandEvent & event);

	DECLARE_EVENT_TABLE()

private:

	wxMenuBar * MenuBar;
	wxStaticBox * Box;
	wxMenu * FileMenu;
	wxMenu * OptionsMenu;
	wxTextCtrl * NameControl;
	wxTextCtrl * PasswordControl;
	wxButton * LoginButton;
	wxPanel * panel;

	sql::Driver * driver;
	sql::Connection * con;
	sql::Statement * stmt;
	sql::ResultSet * res;

	int Kieli;

};

enum
{
	LIST_Box = wxID_HIGHEST + 1,
	MENU_Exit,
	STATIC_Box,
	MENU_ChangeLanguage,
	TEXT_NameBox,
	TEXT_PasswordBox,
	BUTTON_Login,
	STATUS_Bar

};

#endif

Main.cpp

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

#include "Main.h"
#define MAX 255

BEGIN_EVENT_TABLE( MainFrame, wxFrame ) // Event table alkaa

EVT_MENU(MENU_Exit, MainFrame::Exit)
EVT_MENU(MENU_ChangeLanguage, MainFrame::ChangeLanguage)
EVT_BUTTON(BUTTON_Login, MainFrame::Checklogin)

END_EVENT_TABLE() // --.-- loppuu

IMPLEMENT_APP(MainApp)

bool MainApp::OnInit()
{
	MainFrame * MainWin = new MainFrame(wxT("Test application!"), wxPoint(1,1), wxSize(540,380));
	MainWin->Show(TRUE);
	SetTopWindow(MainWin);

	return TRUE;
}

MainFrame::MainFrame(const wxString & title, const wxPoint & pos, const wxSize & size)
: wxFrame((wxFrame*) NULL, -1, title, pos, size)
{
	// Palkki

	CreateStatusBar(1);
	MenuBar = new wxMenuBar();
	FileMenu = new wxMenu();
	OptionsMenu = new wxMenu();
	Kieli = 0;


	// Menu

	FileMenu->Append(MENU_Exit, wxT("&Lopeta ohjelma"), wxT("Lopettaa ohjelman"));
	OptionsMenu->Append(MENU_ChangeLanguage, wxT("&Vaihda kieli (Käytössä Suomi)"), wxT("Vaihtaa kieltä"));
	MenuBar->Append(FileMenu, wxT("Tiedosto"));
	MenuBar->Append(OptionsMenu, wxT("Asetukset"));
	SetMenuBar(MenuBar);

	// Paneeli

	panel = new wxPanel(this, wxID_ANY);

	// Static box

	Box = new wxStaticBox(panel, STATIC_Box, wxT("Kirjautuminen"), wxPoint( 20, 15 ), wxSize(300, 275 ), 0, wxT("Boxi"));

	// Text boxit ja nappi

	NameControl = new wxTextCtrl(panel, TEXT_NameBox, wxEmptyString, wxPoint(130,130), wxSize(170,25),0, wxDefaultValidator, wxT("NameBox"));
	PasswordControl = new wxTextCtrl(panel, TEXT_PasswordBox, wxEmptyString, wxPoint(130,165), wxSize(170,25),wxTE_PASSWORD, wxDefaultValidator, wxT("PasswordBox"));
	LoginButton = new wxButton(panel, BUTTON_Login, wxT("Kirjaudu"), wxPoint(200,220), wxSize(100,25),0,wxDefaultValidator, wxT("LoginButton"));


	try
	{
		driver = get_driver_instance();
		con = driver->connect("tcp://127.0.0.1:3306", "root", "secret");
		con->setSchema("c++");
		stmt = con->createStatement();
		res = stmt->executeQuery("SELECT Nimi FROM ukot");

		while (res->next())
		{
			Box->SetLabel(wxT("Lol"));
		}

		delete res;
		delete stmt;
		con->close();
		delete con;

	} catch (sql::SQLException &e)
	{
	}




}

void MainFrame::Exit(wxCommandEvent & WXUNUSED(event))
{
	Close(TRUE);
}

void MainFrame::ChangeLanguage(wxCommandEvent & WXUNUSED(event))
{
	if ( Kieli == 0 )
	{
		Box->SetLabel(wxT("Login"));

		// Eka menu
		FileMenu->SetLabel(MENU_Exit, wxT("&Exit"));
		FileMenu->SetHelpString(MENU_Exit, wxT("Quits the program"));
		MenuBar->SetLabelTop(0,wxT("File"));

		// Toka menu
		OptionsMenu->SetLabel(MENU_ChangeLanguage, wxT("&Change language (English in use)"));
		OptionsMenu->SetHelpString(MENU_ChangeLanguage, wxT("Changes the language"));
		MenuBar->SetLabelTop(1, wxT("Options"));
		delete LoginButton;
		LoginButton = new wxButton(panel, BUTTON_Login, wxT("Login"), wxPoint(200,220), wxSize(100,25),0,wxDefaultValidator, wxT("LoginButton"));



		Kieli = 1;
	}
	else
	{
		Box->SetLabel(wxT("Kirjautuminen"));

		// Eka menu
		FileMenu->SetLabel(MENU_Exit, wxT("&Lopeta ohjelma"));
		FileMenu->SetHelpString(MENU_Exit, wxT("Lopettaa ohjelman"));
		MenuBar->SetLabelTop(0,wxT("Tiedosto"));

		// Toka menu
		OptionsMenu->SetLabel(MENU_ChangeLanguage, wxT("&Vaihda kieli (Käytössä Suomi)"));
		OptionsMenu->SetHelpString(MENU_ChangeLanguage, wxT("Vaihtaa kieltä"));
		MenuBar->SetLabelTop(1, wxT("Asetukset"));
		delete LoginButton;
		LoginButton = new wxButton(panel, BUTTON_Login, wxT("Kirjaudu"), wxPoint(200,220), wxSize(100,25),0,wxDefaultValidator, wxT("LoginButton"));


		Kieli = 0;
	}

}

void MainFrame::Checklogin(wxCommandEvent & WXUNUSED(event))
{
}

Any help?

Try actually putting something in your catch statement. And if you're not getting anything there then take the old-fashioned approach and just put asserts/couts along your code to see where it dies

catch (sql::SQLException &e)
{
}

Added some code but nope. nothing- If I add cout statements inside to track the error how can I see them if I have graphical form?

Added some code but nope. nothing- If I add cout statements inside to track the error how can I see them if I have graphical form?

I was using couts as an example, the method you want to use to display the message is up to you

Oh, but when I start debugging form doesn't have time to appear as it crashes immediately.

I mean it doesn't even show up before it crashes so its kind of impossible to see the error someway, please suggest something if you got! Sorry for double post.

Then you move onto the next step of debugging. Remove stuff you just added until it stops breaking. Then re-add the code and figure out why it broke. Really, these are basic debugging steps to follow. If it's just utterly dying (I'm not sure what IDE/compiler you're using) then compile with debugging info and gdb the crap out of it.

This part crashes it:

try
{
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "secret");
con->setSchema("c++");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT Nimi FROM ukot");
 
while (res->next())
{
Box->SetLabel(wxT("Lol"));
}
 
delete res;
delete stmt;
con->close();
delete con;
 
} catch (sql::SQLException &e)
{
}

And debugger says

First-chance exception at 0x698eb690 in Test13.exe: 0xC0000005: Access violation reading location 0xcccccccc.
Unhandled exception at 0x698eb690 in Test13.exe: 0xC0000005: Access violation reading location 0xcccccccc.

I think something is wrong with the driver thing

And I also get error Expression cannot be evaluated. I am doing something wrong with class related to sql thing I just don't get it.

And I also get error Expression cannot be evaluated. I am doing something wrong with class related to sql thing I just don't get it.

Frederick2 has some experience in this sort of thing with MS SQL connection. He may be able to help.

regards,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.