Overusing using?

This is a rather simplistic example perhaps but is making habit of using using good style or should it be used judiciously? Thanks.

 //make SQL Server connection and empty destination table using (SqlConnection sqlconn = new SqlConnection(sqlconstr)) { sqlconn.Open(); using (SqlCommand sqlcmd = new SqlCommand(sqlcmdstr, sqlconn)) { sqlcmd.ExecuteNonQuery(); } } //make OLE DB connection to Excel file, bulk copy contents into SQL Server destination table using (OleDbConnection oledbconn = new OleDbConnection(excelconstr)) { oledbconn.Open(); using (OleDbCommand oledbcmd = new OleDbCommand(oledbstr, oledbconn)) { OleDbDataReader dr = oledbcmd.ExecuteReader(); using (SqlBulkCopy bulkcopy = new SqlBulkCopy(sqlconstr)) { bulkcopy.DestinationTableName = tablename; while (dr.Read()) { bulkcopy.WriteToServer(dr); } } } } 

by Zamdrist via /r/csharp

Leave a Reply