Problème pour fermer MS Access lors d'une connexion utilisant ADOX
mchirouze
Messages postés3Date d'inscriptionjeudi 15 novembre 2007StatutMembreDernière intervention 2 janvier 2008
-
2 janv. 2008 à 10:54
mchirouze
Messages postés3Date d'inscriptionjeudi 15 novembre 2007StatutMembreDerniè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
A voir également:
Problème pour fermer MS Access lors d'une connexion utilisant ADOX
mchirouze
Messages postés3Date d'inscriptionjeudi 15 novembre 2007StatutMembreDerniè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)
mchirouze
Messages postés3Date d'inscriptionjeudi 15 novembre 2007StatutMembreDerniè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.