I am making multiple queries to a database over a short period continiously. In the past I have always closed the connection and reopened when I needed to talk to sqlserver again - this served me well. But now when I try to do this over a very short period I get no connections availible messages. I then thought I would just try and keep the connection open for the life of the application, so far so good I haven't run into any problems. I am just wondering what others think of this approch...am I on a short road to disaster?
One other thing I have nocied that I really don't have to call connection open() method, the connection just seem to work without the call - what's the deal with that?
void main()
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = <connection>;
tmr.interval=100;
tmr.Elapsed += new System.Timers.ElapsedEventHandler(tmr_Elapsed);
}
void tmr_elapsed()
{
tmr.Enabled = false;
SqlDataAdapter da = new SqlDataAdapter(query, cn);
da.Fill(dt);
tmr.Enabled = true;
}
C#, sql-server 2000, .net 2.0