Page 1 of 1

Problems of TMyEmbConnection in DLL (7.0.2)

Posted: Fri 13 Apr 2012 05:01
by savagez
I created a TMyEmbConnection in MainApp and use it inside dll, then it showed "invalid class typecast" error,

I searched in forum, and found a workaround which is "create connection inside dll and use the AssignConnect method to share database connection"

but when the connection work under embedded mode, it shows an error
"Cannot run second Embedded server instance for single data folder. Please see details in MyDAC help or MySQL Reference manual"

Any one can help me?

Here is my code

Code: Select all

var
  Child: TForm;
begin
  Child := ShowNokiaForm(Application, self, MyCustomConnection,pIniFile);
  Child.Show;




extern "C" TForm * __declspec(dllexport) __stdcall ShowNokiaForm(TApplication *App, TComponent *Owner, TCustomMyConnection *MyConnection1,TIniFile *pIniFile1)
{
	//--- create a new MDI child window ----
	Application = App;  //将主程序的application付给COM工程的application对象
  InitNet();
  //TCustomMyConnection *MyConnection2;
  TMyConnection *FMyConnection;
  TMyEmbConnection *FMyEmbConnection;

  if (MyConnection1->InheritsFrom(__classid(TMyConnection)))
  {
    FMyConnection=new TMyConnection(NULL);
    FMyConnection->AssignConnect(MyConnection1);
    ;
    MyConnection3=FMyConnection;
  }
  else
  {
    FMyEmbConnection=new TMyEmbConnection(NULL);
    FMyEmbConnection->AssignConnect(MyConnection1);
    
    MyConnection3=FMyEmbConnection;
  }


	TNokiaForm *Child = new TNokiaForm(Owner,MyConnection3,pIniFile1);
	return Child;
}



__fastcall TNokiaForm::TNokiaForm(TComponent* Owner,TCustomMyConnection *MyConnection1,TIniFile *pIniFile1)
	: TForm(Owner)
{
  MyQuery1->Connection = MyConnection1;
  pIniFile2 = pIniFile1;
  MyConnection2 = MyConnection1;

	MyQuery1->FetchAll = false;
	MyQuery1->Close();
	MyQuery1->SQL->Clear();
	if (GroupBy == "")
		MyQuery1->SQL->Add("Select "+FormulaSQLStr+FromStr+ WhereStr);
	else
		MyQuery1->SQL->Add("Select "+GroupBy+","+FormulaSQLStr+FromStr+ WhereStr + " Group by "+GroupBy);
	//MyQuery->SQL->Add(" limit "+IntToStr(limit));
	MyQuery1->Open();
}

Posted: Fri 13 Apr 2012 08:48
by AndreyZ
Hello,
I searched in forum, and found a workaround which is "create connection inside dll and use the AssignConnect method to share database connection"
It's the correct way of sharing one connection.
but when the connection work under embedded mode, it shows an error
"Cannot run second Embedded server instance for single data folder. Please see details in MyDAC help or MySQL Reference manual"
You cannot have two connections to MySQL Embedded, this is a restriction of MySQL Embedded. We cannot influence it. For more information about restrictions of MySQL Embedded, please refer to http://dev.mysql.com/doc/refman/5.1/en/ ... tions.html

Posted: Sun 15 Apr 2012 22:19
by savagez
AndreyZ wrote:Hello,
I searched in forum, and found a workaround which is "create connection inside dll and use the AssignConnect method to share database connection"
It's the correct way of sharing one connection.
but when the connection work under embedded mode, it shows an error
"Cannot run second Embedded server instance for single data folder. Please see details in MyDAC help or MySQL Reference manual"
You cannot have two connections to MySQL Embedded, this is a restriction of MySQL Embedded. We cannot influence it. For more information about restrictions of MySQL Embedded, please refer to http://dev.mysql.com/doc/refman/5.1/en/ ... tions.html
So you mean there is no solution for my situation?
Is there a way to just use the connection instead of "AssignConnect"?

Posted: Tue 17 Apr 2012 14:48
by AndreyZ
The "Cannot run second Embedded server instance for single data folder. Please see details in MyDAC help or MySQL Reference manual" error occurs only if are trying to open several connections to MySQL Embedded with different connection options. Please check that all your connections have the same connection options.