KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a simple application that needs to execute certain queries to get the database schema information. I have written a simple method that executes a query and returns a reader, something like this - public static DbDataReader ExecuteQuery(DbConnection connection,string sql) { DbCommand command = connection.CreateCommand(); command.CommandText = sql; using(command) { return command.ExecuteReader(); } } The calling code does close the connection and dispose the reader and connection appropriately. My question - Is it ok/right to dipose the command instance (as is done via the using block) before iterating the reader? I do not expect any OUT parameters to be populated after closing the reader. Does the ADO.NET API have any strict guidelines regarding this?
Tags (comma-separated)
Save Edits
Cancel