If say I need to run two separate SQL statements against two separate databases. Right now I do (pseudocode):
Try{
declare variable connectionA to DatabaseA
declare variable connectionB to DatabaseB
connectionA.open()
connectionB.open()
declare variable SQLCmdA with ConnectionA and one SQL statement
declare variable SQLCmdB with ConnectionB and another SQL statement
SQLCmdA.executeNonQuery()
SQLCmdB.executeNonQuery()
}
Catch ()
{
print error message
}
Finally(){
connectionA.close()
connectionB.close()
SQLCmdA.Dispose()
SQLCmdB.Dispose()
}
The above seems very clumsy. And if I have three different sql statements, i would need three different SQLCmd variables.
Is there a "standard" way of doing such things, especially in terms of efficiency, performance? if anyone can provide a simple improved pseudocode, that'd be great.
In addition, do I need to worry about implementing Connection Pooling, to conserve resource and speed up the program? If so, how do I implement it in this case?
Thanks!