Access remote database using DataSnap technology in C++ Builder 10.1 Berlin

会有一股神秘感。 提交于 2019-12-31 03:59:29

问题


How to query and get results from remote database using DataSnap technology in C++ Builder 10.1 Berlin ?

I want to build a simple solution having two VCL Forms Applications, like client(1) and server(2), running on two different windows os computers, connected on same local network.

But I cannot accomplish this simple task and this is what I tried to do:

On the server application (2), I use:

TSQLConnection *SQLConnection1;
TSQLQuery *SQLQuery1;

and I will load a SQLite database version 3:

 if (SQLConnection1->Params->IndexOf("Database") == -1)
     {
        SQLConnection1->Params->Add("Database="+Form->DataBaseFile );
     }
     else
     {
        SQLConnection1->Params->Values["Database"] = Form->DataBaseFile;
     }

     try
     {
        SQLConnection1->Connected = true;
     }
     catch (EDatabaseError& E)
     {
       ShowMessage("Exception raised with message" + E.Message);
     }

and execute sql query:

 try
 {
   SQLQuery1->SQL->Text = "query from client app(1)";
   SQLQuery1->Active = false;
   SQLQuery1->ExecSQL();


 }
 catch (Exception& E)
 {
    ShowMessage( "SQLite exception raised with message:\n\n" + E.Message);
    SQLConnection1->Connected = false;
 }

and I need to return SQLQuery1 results back to client app(1)

On the client application I think I should do something like below, but I'm not sure, I don't know how to do this correctly:

TSQLServerMethod *SQLServerMethod1;

SQLServerMethod->SQLConnection = SQLConnection1;

   try{
     SQLServerMethod.ServerMethodName = "TDSUtilityMethods.echoOutStr";
     SQLServerMethod->Params[0]->AsString = "123";
     SQLServerMethod->ExecuteMethod();
     memoOutput->Text = SQLServerMethod->Params[1]->AsString;
  }
   finally{
     SQLServerMethod->Close();
   }

So the purpose is to make a server application(2) which host and execute sql queries from client app(1) which sends the sql query and waits for results. The application(1) which send sql query is a wrapper of chromium client. I tried to achieve all this solution using TIdHTTPServer on sever app(2) and WebSockets from chromium client app(1), and posted a releated question here but implementing WebSocket protocol(encoding/decoding packets) is a bit hard for an amateur developer. And then I found that a easier solution could be using DataSnap technology. I have read about Developing DataSnap Applications, but still not able to build this simple solution, on embarcadero website are described each component, but because I'm amateur developer, I found it confusing and hard to complete a simple task which seems possible and easier to build using DataSnap technology than WebSockets. But now I found hard to implement DataSnap technology, because there is a lot of new things which are confusing without examples.

Please if you know how to do this in C++ Builder 10.1 Berlin, show here a short sample of that.

来源:https://stackoverflow.com/questions/44571004/access-remote-database-using-datasnap-technology-in-c-builder-10-1-berlin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!