Problème pour fermer MS Access lors d'une connexion utilisant ADOX

mchirouze Messages postés 3 Date d'inscription jeudi 15 novembre 2007 Statut Membre Dernière intervention 2 janvier 2008 - 2 janv. 2008 à 10:54
mchirouze Messages postés 3 Date d'inscription jeudi 15 novembre 2007 Statut Membre Dernière intervention 2 janvier 2008 - 2 janv. 2008 à 14:32
Bonjour,


Je travaille sur ce code qui génère une liste des tables dans une base Access (avec les propriétés des tables liées). Je travaille sur VB.NET et j'utilise ADOX.


Tout marche bien, sauf lorsque je dois fermer la connexion. J'ai lu plusieurs articles sur le sujet, et les solutions habituelles proposées fonctionnent sauf lorsque je dois faire appel aux propriétés de ADOX.Table ("Jet OLEDB:Link Datasource" and "Jet OLEDB:Remote Table Name"). Dès que je fais appel à ces propriétées, il m'est impossible de fermer l'accès à la base Access sauf en fermant le logiciel (le fichier .ldb reste).

Des idées ?

Merci !!

Voici mon code :



Dim adoCon As New ADODB.Connection
Dim adoCat As New ADOX.Catalog
Dim adoTbl As New ADOX.Table



        'Connect to database
        adoCon.Open("Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;OLE DB Services=-4;Data Source = C:\Test.mdb")
        adoCat.ActiveConnection = adoCon




        Dim TblList As New System.Data.DataTable
        Dim dc As New System.Data.DataColumn
        dc.ColumnName = "TblName"
        dc.DataType = GetType(String)
        TblList.Columns.Add(dc)
        dc = New DataColumn
        dc.ColumnName = "TblType"
        dc.DataType = GetType(String)
        TblList.Columns.Add(dc)
        dc = New DataColumn
        dc.ColumnName = "LinkDBPath"
        dc.DataType = GetType(String)
        TblList.Columns.Add(dc)
        dc = New DataColumn
        dc.ColumnName = "LinkDBTable"
        dc.DataType = GetType(String)
        TblList.Columns.Add(dc)
        dc.Dispose()
        dc = Nothing




        Dim dr As DataRow = TblList.NewRow()


        'List links
        For Each adoTbl In adoCat.Tables            If adoTbl.Type "LINK" Or adoTbl.Type "TABLE" Then
                dr("TblType") = adoTbl.Type
                dr("TblName") = adoTbl.Name
                dr("LinkDBPath") = adoTbl.Properties("Jet OLEDB:Link Datasource").Value
                dr("LinkDBTable") = adoTbl.Properties("Jet OLEDB:Remote Table Name").Value
                TblList.Rows.Add(dr)
                adoTbl.Properties.Refresh()
                dr = TblList.NewRow()
            End If


        Next




        dr = Nothing
        adoTbl = Nothing
        adoCat.ActiveConnection.Close()
        adoCat = Nothing

5 réponses

cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
2 janv. 2008 à 11:03
Salut,

Pour fermer ta base :

AdoCon.close
Adocon = Nothing

A+
Exploreur

 Linux a un noyau, Windows un pépin

 
0
mchirouze Messages postés 3 Date d'inscription jeudi 15 novembre 2007 Statut Membre Dernière intervention 2 janvier 2008
2 janv. 2008 à 12:10
Salut Exploreur,

Merci, mais ça ne marche pas. La ligne adoCat.ActiveConnection.Close ferme la connexion (tout comme AdoCon.close).
J'ai rajouté AdoCon = Nothing mais ça n'y change rien. Ces solutions marchent bien tant qu'on n'a pas fait appel aux propriétés de ADOX.Table. Après ça, rien ne semble y faire.

(Au fait, j'ai aussi essayé GC.Collect, ça n'y change rien)

A +

MC
0
cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
2 janv. 2008 à 14:04
Euh...là je sèche.....Désolé

A+
Exploreur

 Linux a un noyau, Windows un pépin

 
0
cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
2 janv. 2008 à 14:13
Ah, un dernier petit truc, essaye comme çà :
        
       Set dr = Nothing
       Set adoTbl = Nothing
       adoCat.ActiveConnection.Close()
       Set adoCat = Nothing
       adocon.Close
       Set adoCon = Nothing

A+
Exploreur

 Linux a un noyau, Windows un pépin

 
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
mchirouze Messages postés 3 Date d'inscription jeudi 15 novembre 2007 Statut Membre Dernière intervention 2 janvier 2008
2 janv. 2008 à 14:32
Non, toujours pas ;-(


Merci quand même, mais ça m'a bien l'air d'être un "vrai" bug. La connexion apparaît comme fermée (si l'on fait adoCon.Close VB retourne un message d'erreur), c'est comme si l'appel à ADOX.Table ouvrait une connexion séparée, je n'arrive pas à mettre la main dessus.
0
Rejoignez-nous