DataSnap client shares server-side database connection

Source: Internet
Author: User
A connection (SQLConnection) of the client can share the access connection of the server Method to the database. In this way, a client can connect to a database connection of the unique associated server. Through this shared connection, the client can directly execute SQL statements and stored procedures of the database, and it can be the same as the method called on the server.

A connection (SQLConnection) of the client can share the access connection of the server Method to the database. In this way, a client can connect to a database connection of the unique associated server. Through this shared connection, the client can directly execute SQL statements and stored procedures of the database, and it can be the same as the method called on the server.

A connection (SQLConnection) of the client can share the access connection of the server Method to the database. In this way, a client can connect to a database connection of the unique associated server. Through this shared connection, the client can directly execute SQL statements and stored procedures of the database, it can also be in the same transaction context as the method called on the server.

The implementation of the shared connection is achieved by calling a method of the server to return the TDBXConnection instance. The returned instance is not actually returned to the client. It is still retained on the server, and the SQL statement or stored procedure submitted and executed by the client is completed by the instance. For the convenience of the client implementation, the TDBXPropertyNames of the SQLConnection control of the client can return the call method of the TDBXConnection instance server. the ServerConnection attribute is specified when the client executes SQLConnection. when Open is enabled, a server-side database sharing connection is obtained. For example, the server provides a function: function TServerMethods1.GetShareConn: TDBXConnection, And the ServerConnection attribute is set to 'tservermethods1. getshareconn '.

DataSnap also provides a built-in method DSAdmin. GetConnection to return TDBXConnection, which can be directly used by the client to establish a shared connection. However, this method requires the dbxconnections. ini file to be deployed on the server. During design, you can create a database connection in advance in Data Explorer of IDE, for example, named 'myoracleconnection '. The ServerConnection attribute of the client is set to DSAdmin. GetConnection ("myoracleconnection ").

The use of client shared connections is also very simple. The Driver attribute of the client SQLConnection control is 'datasnap '. Originally, the client cannot directly submit and execute SQL statements or stored procedures. However, after a shared connection is established, the SQLConnection control can be regarded as connected to the database rather than the DataSnap server. We can put the TSQLDataSet control on the client and specify the SQL statement or stored procedure for execution. If we want to return the dataset, then, you can add the TDataSetProvider, TClientDataSet, and other controls. In this way, it is very similar to the previous layer-2 database application development.

When the client uses a shared connection to submit and execute SQL statements or stored procedures, it can still use this SQLConnection to call the server method exposed by the DataSnap server.

Shared connections are not common, but may be useful in some special cases, such as when the client completes database transaction processing. At the same time, shared connections can also reduce the number of concurrent connections to the database, thus effectively reducing the server's resource usage.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.