MyConnection1 was created at designtime, and it was not null.
I added MyConnection1->Database = stDbName; to check whether the db exists, if it doesn't, i catch the exception, and create the database...
So in the code below, when database does not exist, the connect gives an AV...
Code: Select all
MyConnection1->Server = dbIP;
MyConnection1->Database = stDbName;
MyConnection1->Username = stDbUser;
MyConnection1->Password = stDbPass;
if(!fmMain->MyConnection1->Connected)
{
try
{
fmMain->MyConnection1->Connected = true;
}
catch(Exception &exception)
{
MessageBox(GetActiveWindow(),exception.Message.c_str(),"error",MB_OK| MB_ICONSTOP);
if(exception.Message.Pos("42000Unknown database")>0)
{
if(MessageBox(GetActiveWindow(),"Database does not exist. Create?","Question",MB_YESNOCANCEL | MB_ICONQUESTION)==mrYes)
{
MyConnection1->Database = "mysql";
MyConnection1->Connect();
qTmp->SQL->Text = "create database "+stDbName;
qTmp->Execute();
MyConnection1->Database = stDbName;
MyConnection1->Connect();
}
}
}
}
I tested this morning, but did not get the AV...
It seems like the AV comes from an other thread.
When debugging, I get into the catch section ("database does not exist"), the messagebox gets shown, and 500ms after it's show, I get the AV....
Can this possibly come from MyDac ?
Vince