Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Do you check connection on every call to SQL?
Message
 
 
À
11/03/2012 14:44:59
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01537347
Message ID:
01537998
Vues:
28
>>I was speaking in general terms - it's obviously not a good idea to call .Dispose() on an item that will remain in scope and, on that basis, I've never consiously done so (I'd rather not give unexpected behaviour a chance :-} ).
>>Can you show an example of how you are using an SqlDataAdapter in a using block ?
>
>Some declarations:
>
>
>        Public oDataSet As DataSet = Nothing
>        Private oCommand As IDbCommand = Nothing
>        Private oDataAdapter As IDbDataAdapter = Nothing
>
>
>Based on the backend, I have this:
>
>
>            ' Different backends handle it differently
>            Select Case nSQLMode
>
>                ' OleDb
>                Case 1
>                    oDataAdapter = New OleDbDataAdapter
>                    oCommand = New OleDbCommand
>
>                    ' SQLClient
>                Case 2
>                    oDataAdapter = New SqlDataAdapter
>                    oCommand = New SqlCommand
>
>                    ' ODBC
>                Case 3
>                    oDataAdapter = New OdbcDataAdapter
>                    oCommand = New OdbcCommand
>
>            End Select
>
>
>Some initializations:
>
>
>                oCommand.CommandText = tcSQL
>                oDataAdapter.SelectCommand = oCommand
>
>                oDataSet = New DataSet
>
>
>This is where the query happens:
>
>
>                                Using loSQLConnection As New SqlConnection(lcConnectionString)
>                                    oCommand.Connection = loSQLConnection
>                                    oDataAdapter.Fill(oDataSet)
>                                End Using
>
Do you usually close the connection? And if yes, how? The last segment of your code shows that you call Fill() method to fill the dataset. But this, if I understand correctly, leaves the connection open. How do you deal with this?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform