Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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.

share|improve this answer
    
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

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
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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