vb6 - Should RecordSet object be nulified in VB.NET? -
i converting old vb6 app newer vb.net application , see these 3 lines after upgrade:
rs.close() 'upgrade_note: object rs may not destroyed until garbage collected. click more: 'ms-help://ms.vscc.v80/dv_commoner/local/redirect.htm?keyword="6e35bff6-cd74-4b09-9689-3e1a43df8969"' rs = nothing where rs of type recordset so:
dim rs adodb.recordset rs = new adodb.recordset should last
rs = nothing line still exists? or
rs.close() is enough?
with vb.net, pretty never set objects nothing. common in vb6 era, .net it's no longer helpful, , can in rare situations actively harmful. should use finally section of try/catch/finally block (or using block shorthand) make sure objects implement idisposable interface have dispose() function called in timely way, , in case of old ado objects finally block place call .close(). want ado connection object.
in summary, rs = nothing line should not exist, rs.close() isn't enough itself, either.
but that's side issue here. if you're converting vb.net, best thing convert original ado more modern ado.net, more idiomatic vb.net. means using dataset , datareader instead of recordset in first place.
finally, time review queries , make sure using query parameters rather string concatenation. doing this, there lot of old , scary-vulnerable classic-asp , vb6 code out there, , .net migration time plug holes. sql injection isn't fool around with.
Comments
Post a Comment