[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP.net 4 Connecting to remote Access database on Server with IIS

Posted on 2011-10-31
9
Medium Priority
?
400 Views
Last Modified: 2012-05-12
Hi

I am trying to use the following ASP.net VB code to connect to a remote Access database that
resides on a LAN Server. I am getting the error ADODB.Connection not defined. I have never done this before so not sure whether if I am on the right track
Dim adoConn As ADODB.Connection
    Dim adoRst As ADODB.Recordset


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim strConString As String
        Dim strSQL As String

        'assign connection string
        strConString = "Provider=MS Remote;" & _
                       "Remote Server=http://192.168.1.1;" & _
                       "Remote Provider=Microsoft.Jet.OLEDB.4.0;" & _
                       "Data Source=MyRemoteDB;Persist Security Info=False"

        'initialize connection object variable
        adoConn = New ADODB.Connection
        'open connection
        adoConn.Open(strConString, "admin", "")

        strSQL = "Select * from Orders"

        'initialize recordset object variable
        adoRst = New ADODB.Recordset
        With adoRst
            .Open(strSQL, adoConn, , , adCmdText)
            If Not .EOF Then
                Do While Not .EOF
                    'read each record here
                    '...
                    .MoveNext()
                Loop
                .Close()
            End If
        End With

        'destroy recordset object if necessary (or do it when you unload the form)
        'Set adoRst = Nothing

        'destroy connection object if necessary (or do it when you unload the form)
        'Set adoConn = Nothing

    End Sub

Open in new window

0
Comment
Question by:Murray Brown
  • 4
  • 4
9 Comments
 
LVL 12

Expert Comment

by:NormanMaina
ID: 37055481
change the sql connection string to:
strConString ="Provider=MS Remote;" & _ 
           "Remote Server=http://myServerName;" & _
           "Remote Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=c:\somepath\mydb.mdb", _
            "admin", ""

Open in new window

0
 

Author Comment

by:Murray Brown
ID: 37055509
Hi. Thanks but the editor doesn't seem to like that last line. What about the ADODB.Connection?
What Imports.... should I be using?
0
 
LVL 12

Expert Comment

by:NormanMaina
ID: 37055600
Imports system.data.OleDb
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Murray Brown
ID: 37055613
Hi. I already did that. For some reason it still doesn't work. Do I need to also add a reference? Thanks
0
 

Author Comment

by:Murray Brown
ID: 37055630
im
0
 
LVL 85
ID: 37055648
I would strongly advise that you NOT do this with an Access databse. MS Remote is the old "RDS" technolog introduced by MSFT, and is obsolete:

http://www.carlprothman.net/Default.aspx?tabid=93

You would be doing yourself a very big favor if you moved the web-based database to a true server database and set that up to allow remote connections. Otherwise, you're just asking for troubles (corrupt data, invalid updates/inserts/retrievals, and vanishing databases).

With that said: Are you sure the Jet.OLEDB.4.0 provider is installed on the remote server?

Have you tried removing the "Persist Security Info" stuff?

0
 
LVL 12

Expert Comment

by:NormanMaina
ID: 37055657
can you add a catch try block between the adoConn.Open line of code and post it here.

Try this code:


'initialize connection object variable
        adoConn = New ADODB.Connection(strConString)
        'open connection
Try
        adoConn.Open
        strSQL = "Select * from Orders"

        'initialize recordset object variable
        adoRst = New ADODB.Recordset
        With adoRst
            .Open(strSQL, adoConn, , , adCmdText)
            If Not .EOF Then
                Do While Not .EOF
                    'read each record here
                    '...
                    .MoveNext()
                Loop
                .Close()
            End If
catch ex as exception
messagebox.show(ex.message)
End Try

End With

Open in new window

0
 
LVL 12

Accepted Solution

by:
NormanMaina earned 2000 total points
ID: 37055693
now i see your problem.

Seems you have to add a reference to system.data and system.data.OleDb

That said -I hope you doing this for training and not deployment of a production environment.
For remote access you need to store your data in a database like sql server -and you can download the free version,sql express versions from the Microsoft sites.
0
 

Author Closing Comment

by:Murray Brown
ID: 37055808
Thanks very much
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question