Environment is : Window 7, Visual studio 2010 vb.net Frame work 3.5, ArcObject 10.0 .net sdk.
I have used the below code in arcobject. BaseCommand implementation (see the full code in the attached doc) to access the value from the given .accdb file. The code successfully ran and displayed the expected result, when click the command button in ArcMap - ArcGIS Desktop 10.0. , after 10 or 20 seconds ArcMap shows the attached error message.
Public Overrides Sub OnClick()
Dim sAccdbPath As String = "" ' "C:\ProgramData\MapManager\Resources\Project\MapManagerProject.accdb"
Dim pFileOpen As New System.Windows.Forms.OpenFileDialog
If pFileOpen.ShowDialog() = Windows.Forms.DialogResult.OK Then sAccdbPath = pFileOpen.FileName
If Not String.IsNullOrEmpty(sAccdbPath) AndAlso System.IO.File.Exists(sAccdbPath) Then
Dim sConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & sAccdbPath & ";Persist Security Info=False;"
Dim sSQL As String = "" '"SELECT * FROM MgrVersion"
sSQL = InputBox("Enter simple select query : ", "Read .accdb database")
Using connection As New OleDb.OleDbConnection(sConnString)
Dim pCmd As New OleDb.OleDbCommand(sSQL, connection)
Dim pRdr As OleDb.OleDbDataReader = Nothing
Try
pCmd.Connection.Open()
pRdr = pCmd.ExecuteReader()
If pRdr.HasRows Then
pRdr.Read()
MsgBox(pRdr.Item(0))
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Using
Else
MsgBox("Invalid file")
End If
End Sub
PS: Arcobject 10.0 alos crash after connect the .accdb file using oledb connection.
Even deploy this dll in to the banlk arcgis desktop 10.0 installed machine, there also happeing the same.
Kindly help to clear this issue.
what's the version of Windows 32 or 64 bit?
If you have 64bit: what's the version installed driver Access 32bit or 64bit ?
Have you compiled your dll with the ANY CPU ?
It appears that you are using pure Microsoft .NET libraries to open your OleDB connection.
Try to use the ESRI libraries and see if you still get the error. Documentation on how to use OleDB connections with ArcObjects is below:
DataSourcesOleDB
http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//001p0000000t000000
FdoAdoConnection CoClass
Object Model Diagram - DataSourcesOleDB
http://resources.arcgis.com/en/help/arcobjects-net/pdf/DataSourcesOleDBObjectModel.pdf