getConnection([uid], [pwd], [Function]) Method
Retrieves a new connection from the connection pool, creating a new connection if the pool is empty.
Parameters
| Type | Name | Description |
|---|---|---|
|
String |
uid |
Specifies the username. |
|
String |
pwd |
Specifies the password. |
|
Function |
callback |
Specifies the optional callback function. |
Returns
A connection object is returned.
Remarks
This method can be synchronous or asynchronous. Specify a callback function to use this method asynchronously, as follows:
function(err, conn)
{
};
Example
The following SAP HANA Cloud example creates a connection pool and retrieves a new connection:
var pool = hana.createPool("ServerNode=myhost-hanacloud.ondemand.com:443;uid=myusername;pwd=mypassword");
var conn = pool.getConnection();
The following SAP HANA Cloud example creates a connection pool, retrieves a new connection for user1, returns it to the pool, then repurposes it for user2:
var pool = hana.createPool("ServerNode=myhost-hanacloud.ondemand.com:443;uid=user1;pwd=password1");
var conn = pool.getConnection(); // Retrieve a connection for user1.
conn.disconnect(); // Return the connection to the pool.
conn = pool.getConnection("user2", "password2"); // Retrieve a connection for user2, re-using the connection created earlier, and automatically issue CONNECT "user2" PASSWORD "password2" to change the user for that connection.