Solved

Idisposable interface and the using statement in SQL

Posted on 2006-10-26
4
233 Views
Last Modified: 2012-06-27
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?
0
Comment
Question by:7of9121098
  • 4
4 Comments
 
LVL 18

Expert Comment

by:DarrenD
Comment Utility
Hi,

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

Darren
0
 
LVL 18

Accepted Solution

by:
DarrenD earned 50 total points
Comment Utility
Here is one link for the first part of you question.

http://blog.devstone.com/aaron/archive/2004/06/03/184.aspx
0
 
LVL 18

Expert Comment

by:DarrenD
Comment Utility
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
 
LVL 18

Expert Comment

by:DarrenD
Comment Utility
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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now