Idisposable interface and the using statement in SQL

I'm having problem finding a good Vb.net example that shows how to dispose a sql connection via the idisposable interface. Also with the 'using' statement. Does anyone have a good small example using both of these keywords?
7of9121098Asked:
Who is Participating?
 
DarrenSenior Software EngineerCommented:
Here is one link for the first part of you question.

http://blog.devstone.com/aaron/archive/2004/06/03/184.aspx
0
 
DarrenSenior Software EngineerCommented:
Hi,

As far as I know you cannot use the 'using' statement in VB.NET only C#

Darren
0
 
DarrenSenior Software EngineerCommented:
Ah...I was only thinking about .NET 1.1


I amwrong in VB.NET 2.0 you can use Using

http://pluralsight.com/blogs/fritz/archive/2005/04/28/7834.aspx
0
 
DarrenSenior Software EngineerCommented:
Here is a way to get Using working in VB.NET 1.1


Dim conn As SqlConnection = New SqlConnection(dsn)
Try
Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM Employees", conn)
Try
conn.Open()
rdr = cmd.ExecuteReader()
While rdr.Read()
Console.WriteLine(rdr(0))
End While
Finally
If Not cmd is Nothing Then
cmd.Dispose()
End If
End Try
Finally
If Not conn is Nothing Then
conn.Dispose()
End If
End Try


Hope this Helps

Darren
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.