locked
connection polling? RRS feed

  • Question

  • User888441741 posted

    hi there...

    i need to know whether i'm following the best practice or creating polling

    i'm using DAAB ver 2

     

      public static int Update(string spName, params SqlParameter[] parameter)
            {            
                Database db = DatabaseFactory.CreateDatabase(dataProvider); // ???
                DbCommand dbCommand = db.GetStoredProcCommand(spName);
                AssignParameters(dbCommand, parameter);
                return db.ExecuteNonQuery(dbCommand);         
                
            }
            #endregion
    
            public static IDataReader GetReader(string spName, params SqlParameter[] parameter)
            {
                Database db = DatabaseFactory.CreateDatabase(dataProvider); // ???
                IDataReader dr;
                DbCommand dbCommand = db.GetStoredProcCommand(spName);
                AssignParameters(dbCommand, parameter);
                dr = db.ExecuteReader(dbCommand);
                return dr;
            }
    
            public static DataSet GetDataSet(string spName, params SqlParameter[] parameter)
            {
                Database db = DatabaseFactory.CreateDatabase(dataProvider); // ???
                DataSet ds;
                DbCommand dbCommand = db.GetStoredProcCommand(spName);
                AssignParameters(dbCommand, parameter);
                ds = db.ExecuteDataSet(dbCommand);
                return ds;
            }
    

     

       Database db = DatabaseFactory.CreateDatabase(dataProvider); // ???

    the above createdatabase will create polling? the above 3 mothods are generic and this will be called in my application may be thousand times.... am i using in a right way?

    just curious to know.

    thanks.

    thanks.

    Thursday, October 18, 2007 3:36 PM

Answers

  • User214117797 posted

     I will try explain a bit more.

    When you connect to a database you use the ADO.NET  framework, BUT you still supply a connection string to tell ADO.NET where the server is, the database name, and the credentials. If you use the same connection string throughout your application then you application will make use of connection pooling as you will only every be creating the same connection. If you say you got 2 different connection strings, then  there will be 2  distinct connections.

    Have a read of this

    http://aspalliance.com/1099_Understanding_Connection_Pooling_in_NET.2 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 19, 2007 10:38 AM

All replies

  • User214117797 posted

    i need to know whether i'm following the best practice or creating polling

     

    Database connection pooling does really concern coding at all because it is determined solely by the connection string.

     To make use of connection pooling just make sure you connection strings are always the same.

    Thursday, October 18, 2007 10:31 PM
  • User888441741 posted

    i need to know whether i'm following the best practice or creating polling

    Database connection pooling does really concern coding at all because it is determined solely by the connection string.

     To make use of connection pooling just make sure you connection strings are always the same.

    i'm not sure i understood your reply.

    how is my code looks like ? am i doing the way it suppose to do or my code will create problem of connection?

    Friday, October 19, 2007 9:46 AM
  • User214117797 posted

     I will try explain a bit more.

    When you connect to a database you use the ADO.NET  framework, BUT you still supply a connection string to tell ADO.NET where the server is, the database name, and the credentials. If you use the same connection string throughout your application then you application will make use of connection pooling as you will only every be creating the same connection. If you say you got 2 different connection strings, then  there will be 2  distinct connections.

    Have a read of this

    http://aspalliance.com/1099_Understanding_Connection_Pooling_in_NET.2 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 19, 2007 10:38 AM
  • User888441741 posted

    thanks for the explanation and link and i will read that link.

    so by look at my code the way i'm using the same connection string all the time and i have only one connection string in my entire application.

    so i'm fine the way i'm using ?

    Friday, October 19, 2007 10:50 AM
  • User214117797 posted

    You would be fine if you are never changing your connection string.

    Also take note of the principle of opening your connection as late as possible, and closing/disposing your connection as soon as possible. 

     

    Friday, October 19, 2007 11:40 AM