mgartman
11-23-2004, 02:13 AM
Hello,
I've been working with opening a datareader and creating error handling for it. Is it enough to just open the Datareader in a Try block and not close it in the finally?
I can't seem to find a way to close the reader in thefinally block, if I create the Datareader in the try block then it is out of scope in the finally. If I create the datareader out of the error handling, VS throws and error saying that I can't close an unassigned variable.
Will the datareader close automatically if there is an error before it reaches it's .Close(); in the try block?
Is there a better way to do this?
Thanks!
Matt
I've been working with opening a datareader and creating error handling for it. Is it enough to just open the Datareader in a Try block and not close it in the finally?
I can't seem to find a way to close the reader in thefinally block, if I create the Datareader in the try block then it is out of scope in the finally. If I create the datareader out of the error handling, VS throws and error saying that I can't close an unassigned variable.
Will the datareader close automatically if there is an error before it reaches it's .Close(); in the try block?
Is there a better way to do this?
Thanks!
Matt