Does DataAdapter.Fill() close its connection when an Exception is thrown?
Posted
by motto
on Stack Overflow
See other posts from Stack Overflow
or by motto
Published on 2010-03-18T19:41:22Z
Indexed on
2010/03/18
19:51 UTC
Read the original article
Hit count: 444
Hi, I am using ADO.NET (.NET 1.1) in a legacy app. I know that DataAdapter.Fill() opens and closes connections if the connection hasn't been opened manually before it's given to the DataAdapter.
My question: Does it also close the connection if the .Fill() causes an Exception? (due to SQL Server cannot be reached, or whatever). Does it leak a connection or does it have a built-in Finally-clause to make sure the connection is being closed.
Code Example:
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim ds As New DataSet
cmd.Connection = New SqlConnection(strConnection)
cmd.CommandText = strSQL
da.SelectCommand = cmd
da.Fill(ds)
© Stack Overflow or respective owner