Since IIS assigns a workflow for each request, I intend to create a new object to serve each request. I have 2 questions:
Is it efficient to create a new object to serve each request? (is there even an alternative?)
It is thread safe, efficient, and best practice for creating a new connection and open and close it for each request, as shown below:
using (MySqlConnection conn = new MySqlConnection (ConfigurationManager.ConnectionStrings ["MySqlConnectionString"]. ConnectionString))
{
conn.Open ();
MySqlCommand cmd = new MySqlCommand ("SELECT password FROM Admin WHERE username = '" + username + "'", conn);
object dbp = cmd.ExecuteScalar ();
conn.Close ();
}
PS. this example is taken from this site. I am using oracle db.
Thanks: Matti
source
share