---
title: "how use the dispose method for close the connection"  
description: "how use the dispose method for close the connection"  
author: "Rajesh Goswami"  
published: 2010-11-10  
updated: 2013-02-25  
canonical: https://www.mindstick.com/forum/87/how-use-the-dispose-method-for-close-the-connection  
category: "ado.net"  
tags: ["ado.net"]  
reading_time: 2 minutes  

---

# how use the dispose method for close the connection

[explain](https://www.mindstick.com/forum/157854/what-is-system-debugging-explain-some-system-debugging-tools-used-in-modern-computer-systems) it

## Replies

### Reply by Shankar M

Post is removed by the User.

### Reply by Shankar M

Hi Rajesh,\
You don't need to explicitly close the connection that is opened, You can use the Using Clause.\

```
using(SqlConnection sqlcon = new SqlConnection(constring))  {   }
```

\
The leverage of using it is the resources tied up to it are freed automatically with out explicitly calling theDispose() Method.\
Thanks,Shankar

### Reply by Shankar M

Hi Rajesh,\
You don't need to explicitly close the connection that is opened, You can use the Using Clause.

```
using(SqlConnection sqlcon = new SqlConnection(constring))  {   }
```

\
The leverage of using it is the resources tied up to it are freed automatically with out explicitly calling theDispose() Method.\
Thanks,Shankar

### Reply by yash Singh

Dispose() method permanently removes connection object from memory and the resource no longer exists for any further processing.

\
string constring = "Server=(local);Database=my; User Id=sa; Password=sa";\
SqlConnection sqlcon = new SqlConnection(constring);\
sqlcon.Open(); // connection is open

try\
{\
// code here which will be execute\
}\
catch\
{\
// code will be execute when error occurred in try block\
}\
finally\
{\
sqlcon.Dispose(); // close and desroy the connection object\
}


---

Original Source: https://www.mindstick.com/forum/87/how-use-the-dispose-method-for-close-the-connection

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
