LeadSquared Developer Centre

ON THIS PAGE

Connect to Your Database Using MS SQL Proxy with Fixed IP Address


Lapps provide node-mssql node package to connect with MS SQL host. It is exposed via a library function that will ensure that your DB request are going via a fixed IP address. The same IP address can be whitelisted in the client DB server to ensure that the requests are coming from a known and expected source, in this case, our Lapps.

We have exposed the new function as ls.lib.mssqlproxy.query. Below is the signature of the function –

ls.lib.mssqlproxy.query(connectionOptions, queryStatement,callback=null)

Below are the parameters description in detail

connectionOptions

Defines the connection configuration to make a database connection. Below are the four properties expected –

let connectionOptions = {
"user": "db user",
"password": "db password",
"server": "host",
"database": "DB Name"
}

queryStatement

Query statement to be executed against the DB, which is passed a string. Ensure that the sting is a valid string and single and double quotes are handled correctly.

let queryStatement = "select COl1,Col2 from TableName where Col3='ABC'"

callback

callback is optional. It returns two parameters, “error” and “response”. In case callback is not passed, the function returns a “Promise”.

 

Timeout

The maximum timeout for the query is set as 3000 ms.

 

IP Addresses

Note: To obtain the fixed IP address for your Lapps, please reach out to your account manager, or write to support@leadsquared.com.

 

Complete Sample Code

callback based approach

let connectionOptions = {
"user": "db user",
"password": "db password",
"server": "host", 
"database": "DB Name"
}
​
let queryStatement = "select COl1,Col2 from TableName where Col3='ABC'"
​
ls.lib.mssqlproxy.query(connectionOptions, queryStatement,(error,res)=>{
if(error){
//handle error here
ls.log.Error("error occured",error)

} else {
// handle successful response here
ls.log.Info("got data",res)
}
});

 

Promise Based Approach

let connectionOptions = {
"user": "db user",
"password": "db password",
"server": "host", 
"database": "DB Name"
}
​
let queryStatement = "select COl1,Col2 from TableName where Col3='ABC'"
​
ls.lib.mssqlproxy.query(connectionOptions, queryStatement)
.then((res)=> {
// handle successful response here
ls.log.Info("got data",res)
})
.catch((error)=> {
//handle error here
ls.log.Error("error occured",error)
})

 

On this page

© 2024 by MarketXpander Services Pvt Ltd. All Rights Reserved.