Solved

Idisposable interface and the using statement in SQL

Posted on 2006-10-26
4
278 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 50 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
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 …
Suggested Courses

623 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