2

I am trying to connect to an MS Access database from a program I have written in VB.Net with ArcObjects 10.0. My MS Access database is not a personal geodatabase so apparently I have to connect to Access using an OLEDBWorkspaceFactory.

Dim propset As IPropertySet2 = New PropertySet
propset.SetProperty("CONNECTIONSTRING", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & txtbox1.Text & ";User Id=admin;Password=;")

Dim oleWorkspace As IWorkspaceFactory2 = New OLEDBWorkspaceFactory
Dim m_workspace As IWorkspace2

If oleWorkspace IsNot Nothing Then m_workspace = oleWorkspace.Open(propset, 0)

The above code works except for one minor detail. When I call oleWorkspace.Open(propset, 0) I get the ArcGIS Database Connection dialogue asking what driver to use and for connection information (which I have already provided in my propertyset).

Is there a way to avoid this dialogue?

3

You should be able to use the AccessWorkspaceFactory co-class even though it's not a personal geodatabase. You could also use ADO.NET. I am not sure why your code isn't working but I do know that working with property sets is an exercise in frustration.

  • I originally did it with the AccessWorkspaceFactory, but any joins I try to create (using memoryrelationshipclass) do not work because my tables do not have objectid's. – Brian Jun 12 '12 at 13:01
0

Is the username actually 'admin' and password blank?

Try removing those parameters from your property set. I usually don't include them if the db is not password protected. Also verify that your txtbox1.Text string is what you expect it to be.

0

I would use ADO.NET. If you are just trying to access information from a normal database, use the methods that .NET has packaged within their framework.

Dim connectionString As String
    Dim cnn As OleDbConnection
    connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=yourdatabasename.mdb;"
    cnn = New OleDbConnection(connectionString)
    Try
        cnn.Open()
        MsgBox("Yeah, that's cool. You opened me. Kudos.")
        cnn.Close()
    Catch ex As Exception
        MsgBox("That's right, crawl back into the hole you came from. Fail.")
    End Try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.