Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Do you check connection on every call to SQL?
Message
De
10/03/2012 03:58:12
 
 
À
09/03/2012 13:37:02
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01537347
Message ID:
01537891
Vues:
30
>>First, thank you for the sample code. A couple of things I don't understand. Why in your code nConnectionString is numeric (I presume that prefix n stands for numeric)? What is the oCommand?
>>
>>Here is the segment of my code where I would like to apply your (connection pool) approach:
>>
>>
>>   string sqlSelectString = "select * from mytable where 1=1";
>>   SqlDataAdapter oDataAdapter = new SqlDataAdapter( sqlSelectString, connectionString);
>>   DataSet dsDataSet = new DataSet();
>>   oDataAdapter.Fill( dsDataSet);
>>
>>
>>What is not clear is how do I create data adapter (oDataAdapter) other than how it is in my code. Again, thank you.
>
>I have some specific items in that sample that are related to my framework.
>
>Basically, what you have in there does it. It's all in the background. If that command works, then, all is fine.
Use:
string sqlSelectString = "select * from mytable where 1=1";
            DataSet dsDataSet;
            using (SqlDataAdapter oDataAdapter = new SqlDataAdapter(sqlSelectString, connectionString))
            {
                dsDataSet = new DataSet();
                oDataAdapter.Fill(dsDataSet);
            }
which is pretty much the equivalent of:
           {
                SqlDataAdapter oDataAdapter = new SqlDataAdapter(sqlSelectString, connectionString);
                try
                {
                    dsDataSet = new DataSet();
                    oDataAdapter.Fill(dsDataSet);
                }
                finally
                {
                    if (oDataAdapter != null)
                        oDataAdapter.Dispose();
                }
            }
Note that generally you should *not* declare the IDisposable (in this case oDataAdapter) outside the using statement. If you do that it will remain in scope even though it has been disposed.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform