code_junkie

ASP.NET logic / connection pooling and error handing

Nov 12th, 2011
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. using (SqlConnection conn = new SqlConnection(this.connectionString))
  2. {
  3. using (SqlCommand cmd = conn.CreateCommand())
  4. {
  5. cmd.CommandText = "LoadFromRepository";
  6. cmd.CommandType = CommandType.StoredProcedure;
  7. cmd.Parameters.AddWithValue("@ID", fileID);
  8.  
  9. conn.Open();
  10. using (SqlDataReader rdr =
  11. cmd.ExecuteReader(CommandBehavior.CloseConnection))
  12. {
  13. while (rdr.Read())
  14. {
  15. // do something with read data
  16. }
  17. }
  18. }
  19. }
Add Comment
Please, Sign In to add comment