Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Idisposable interface and the using statement in SQL

Posted on 2006-10-26
4
Medium Priority
?
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
4 Comments
 
LVL 18

Expert Comment

by:DarrenD
ID: 17818096
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 200 total points
ID: 17818110
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
ID: 17818173
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
ID: 17818174
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

670 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