EAccessViolation on connect

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
vindac
Posts: 20
Joined: Tue 18 Mar 2014 16:44

EAccessViolation on connect

Post by vindac » Tue 18 Mar 2014 16:49

I have a single threaded VCL application.

Code: Select all

        MyConnection1->Server = dbIP;
        MyConnection1->Database = stDbName;
        MyConnection1->Username = stDbUser;
        MyConnection1->Password = stDbPass;
        MyConnection1->Connect(); // gives an Access Violation + an  EAccessviolation.
Two questions:
1) how is an AV possible in this line? (single threaded app);
2) what is that EAccessViolation and where does it come from? Is that mydac specific?

Thanks,
vindac

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: EAccessViolation on connect

Post by AlexP » Thu 20 Mar 2014 14:04

Hello,

Please run the following code and let us know the result:

Code: Select all

	TMyConnection *MyConnection = new TMyConnection(NULL);
	try
	{
		MyConnection->Server = "db";
		MyConnection->Port = 3306;
		MyConnection->Username = "root";
		MyConnection->Password = "root";
		MyConnection->Connect();
	}
	__finally
	  {
		 MyConnection->Free();
	  }
AV can occur for several reasons. One of them is an attempt to work with not created object instance (MyConnection1 == NULL)

vindac
Posts: 20
Joined: Tue 18 Mar 2014 16:44

Re: EAccessViolation on connect

Post by vindac » Fri 21 Mar 2014 09:11

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

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: EAccessViolation on connect

Post by AlexP » Fri 21 Mar 2014 13:23

If a database doesn't exist, then the server returns an error (not AV) when attempting to connect to a nonexistent database . After the error is raised, no AV occurs (even in a while). Please send your sample reproducing the problem to alexp*devart*com .

Post Reply