18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
Close DB Connection
In my code I have several tests to check the state of the database is as expected. Each time an SQL command is executed I open a new connection to the database, then issue the command.
Is there a mechanism for closing the connection to the database.
My sqlserver memory usage increases rapidly over a test suite.
An example of my code is:
Donna
Is there a mechanism for closing the connection to the database.
My sqlserver memory usage increases rapidly over a test suite.
An example of my code is:
<browser>
function getDB()
{
//These parameters enable us to connect to the database directly to ensure that data has been updated as expected
$MachineName = "MACAAA124"
$WebServerUsername = "WebServer";
$WebServerPassword = "password99";
$Database = "AnimalTracking";
//$MachineName = "macaaa113" //Andys machine details
//$WebServerUsername = "sa"; //Andys machine details
//$WebServerPassword = "password"; //Andys machine details
//$Database = "AnimalTrackingRelease"; //Andys machine details
$JTDSDriver = "net.sourceforge.jtds.jdbc.Driver";
$JTDSURL = "jdbc:jtds:sqlserver://" + $MachineName + ";databaseName=" + $Database + ";portNumber=1433;instanceName=SQLEXPRESS;";
$MicrosoftDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
$MicrosoftUrl = "jdbc:sqlserver://" + $MachineName + ";databaseName=" + $Database + ";portNumber=1433;instanceName=SQLEXPRESS;";
return _getDB($MicrosoftDriver, $MicrosoftUrl, $WebServerUsername, $WebServerPassword);
}
</browser>
<browser>
function adHocQueryMicrosoft(sqlString, retColumn)
{
var db = getDB();
return (db.select(sqlString)[0][retColumn]);
}
</browser>
function postCattleDeleteTest($piccode)
{
var $rowCount;
_set($rowCount, adHocQueryMicrosoft("SELECT COUNT = COUNT(*) FROM operator.cattle c, operator.properties p WHERE property_pic_code = '" + $piccode + "' AND c.sex_id = 1 AND c.surrogate_dam_identity_id IS NULL AND c.sire_identity_id IS NULL AND c.property_id = p.property_id AND c.row_deleted_flag = 1", "COUNT"));
_assertEqual("0", $rowCount, "Valid Male Unknown Parents: Row Deletion has not been successful");
}
postCattleDeleteTest(107999700);
CheersDonna
Comments
I think there may be tiny errors on the URL which u r using. What i use is like this:
var db =
_getDB("com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver://machine_name:1433;databasename=database_name;", "username", "password");
If u r using SQL Server 2005, i dont think u need to add instance name to the URL. My above URL works perfect every time. U can try this once.
Regards,
Ashvin.
jdbc:sqlserver://' "+ $MachineName +" ';databaseName=' "+ $Database +" ';portNumber=1433;
Note: Double quotes("") will imediately end your string and everything written after that is complete waste. Instead you need to use single qoutes like this ' " +variable_name+ " '.
I hope this will help you.
Regards,
Ashvin.
Have a look at this thread.
http://sahi.co.in/forums/viewtopic.php?id=250
The db connection not getting closed persisted in the older version. I have no idea of the latest version and I think Narayan will be the right person to comment on this further.
Regards,
Pankaj.