There is no need
Connection.Open
Before calling Method
Adapter.Fill(Dataset)
like
public override DataSet getSMCommentedSubmission(string prodID, string salesID) { using (SqlConnection cn = new SqlConnection(this.ConnectionString)) { SqlCommand cmd = new SqlCommand("sp_WB_Submission", cn); SqlDataAdapter adp = new SqlDataAdapter(cmd); DataSet dset = new DataSet(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@SqType", SqlDbType.Int).Value = 48; cmd.Parameters.Add("@PubPlanID", SqlDbType.Int).Value = null; cmd.Parameters.Add("@TypeID", SqlDbType.Int).Value = null; cmd.Parameters.Add("@Title", SqlDbType.VarChar).Value = null; cmd.Parameters.Add("@CommentID", SqlDbType.Int).Value = null; cmd.Parameters.Add("@ThemeText", SqlDbType.VarChar).Value = null; cmd.Parameters.Add("@StorySynopsys", SqlDbType.VarChar).Value = null; cmd.Parameters.Add("@Status", SqlDbType.VarChar).Value = null; cmd.Parameters.Add("@Comments", SqlDbType.VarChar).Value = null; cmd.Parameters.Add("@TimeStamp", SqlDbType.SmallDateTime).Value = null; cmd.Parameters.Add("@PublisherID", SqlDbType.Int).Value = null; cmd.Parameters.Add("@PermissionType", SqlDbType.VarChar).Value = null; cmd.Parameters.Add("@Checked", SqlDbType.VarChar).Value = null; cmd.Parameters.Add("@SMStatus", SqlDbType.VarChar).Value = null; cmd.Parameters.Add("@PMStatus", SqlDbType.VarChar).Value = null; cmd.Parameters.Add("@ProductionManagerID", SqlDbType.VarChar).Value = prodID; cmd.Parameters.Add("@SalesManagerID", SqlDbType.VarChar).Value = salesID; cmd.Parameters.Add("@StoryID", SqlDbType.Int).Value = null; cmd.Parameters.Add("@Review", SqlDbType.Int).Value = null; adp.Fill(dset); return dset; } }
When locking on a value type it gets boxed, meaning a new object instance is allocated and passed to the lock statement. Thus every time you lock on a value type, you're locking on a new object. Here is an example of bad code:
private bool flag = false;
public void Method1()
{
lock(flag)
...
}
We need to use either “using” or explicitly close the connection if we use the datareader.
Otherwise, it will lead to Connection Pool error. See the underlined text below:
However, there are other cases where it is unclear when to close the connection. An example is the ExecuteReader method. This method returns an object that implements the IDataReader interface. The Database base class has a default implementation that returns a DbDataReader object. DbDataReader objects are designed to read specific portions of the data as needed, which requires an open connection. In other words, it is unknown when the application no longer needs the DbDataReader. If the Data Access Application Block methods close the connection before returning the DbDataReader, the DbDataReader becomes useless to the client code. Instead, the DbDataReader methods indicate to the underlying ADO.NET call to automatically close the connection when the DbDataReader is finished. In this situation, it is considered a best practice for the application to ensure that the DbDataReader is closed in a timely fashion, either by explicitly closing the reader with the DbDataReader.close method or by forcing the disposal of the DbDataReader, which results in the Close method being called.
The following code demonstrates a call to the ExecuteReader method. The using statement (Using in Visual Basic) ensures that the DbDataReader object is disposed, which closes the DbDataReader object.
[C#]
Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetSqlStringCommand("Select Name, Address From Customers");
using (IDataReader dataReader = db.ExecuteReader(dbCommand))
// Process results
when u are creating a control, and u decides that a property or a event should not be displayed in property window.
System.ComponentModel.BrowsableAttribute is there for you, to do the above.
Eg:
private string text;
[Browsable(false)] // True is default public string Text { get { return text; } set { text = value; } }