473,395 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Remote connection 3709 Error

Hello again everyone! I'm having an error trying to retrieve things into a form from a database. I'm just learning, so I'm using the Northwind template that access has, but I'm getting an error that I can't figure out. I let the connection establish during the form_load event, and I get a msgbox confirmation that the connection is established, but when I try to retrieve fields I get "There was an error retrieving information from the database. 3709, The connection cannot be used to perform this operation. It is either closed or invalid in this context." If anyone can decipher what I'm doing wrong, I'd be ecstatic...2 hours trying and I'm still stumped.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Dim remoteConnection As New ADODB.Connection
  5. Dim rsEmployees As New ADODB.Recordset
  6.  
  7. Private Sub Form_Load()
  8.     connect
  9.     SetRecordSet
  10. End Sub
  11.  
  12. Private Sub Form_UnLoad(Cancel As Integer)
  13.     Disconnect
  14. End Sub
  15.  
  16. Public Sub Disconnect()
  17.  
  18.     On Error GoTo ConnectionError
  19.  
  20.     rsEmployees.Close
  21.     Exit Sub
  22. ConnectionError:
  23.     MsgBox "There was an error closing the database." & _
  24.         Err.Number & ", " & Err.Description
  25.  
  26. End Sub
  27. Private Sub connect()
  28. On Error GoTo ConnectionError
  29.     Dim remoteConnection As New ADODB.Connection
  30.     With remoteConnection
  31.         .Provider = "Microsoft.ACE.OLEDB.12.0"
  32.         .Open "C:\Home\Northwind 2007.accdb"
  33.     End With
  34.  
  35.     MsgBox "Remote Connection successfully established."
  36.  
  37.     Exit Sub
  38.  
  39. ConnectionError:
  40.     MsgBox "There was an error connecting to the database. " & Chr(13) _
  41.         & Err.Number & ", " & Err.Description
  42. End Sub
  43.  
  44. Public Sub SetRecordSet()
  45.     Dim sql As String
  46.     On Error GoTo DbError
  47.  
  48.     sql = "select * from Employees"
  49.  
  50.     rsEmployees.CursorType = adOpenKeyset
  51.     rsEmployees.LockType = adLockReadOnly
  52.  
  53.     rsEmployees.Open sql, remoteConnection, _
  54.         , , adCmdText
  55.  
  56.     If rsEmployees.EOF = False Then
  57.         Me.txtAddress = rsEmployees.Fields.Item("address")
  58.         Me.txtBusinessPhone = rsEmployees.Fields.Item("Business Phone")
  59.         Me.txtCity = rsEmployees.Fields.Item("City")
  60.         Me.txtCompany = rsEmployees.Fields.Item("Company")
  61.         Me.txtCountry = rsEmployees.Fields.Item("Country/Region")
  62.         Me.txtEmail = rsEmployees.Fields.Item("E-mail Address")
  63.         Me.txtFaxNumber = rsEmployees.Fields.Item("Fax Number")
  64.         Me.txtFirstName = rsEmployees.Fields.Item("First Name")
  65.         Me.txtHomePhone = rsEmployees.Fields.Item("Home Phone")
  66.         Me.txtJobTitle = rsEmployees.Fields.Item("Job Title")
  67.         Me.txtLastName = rsEmployees.Fields.Item("Last Name")
  68.         Me.txtMobilePhone = rsEmployees.Fields.Item("Mobile Phone")
  69.         Me.txtNotes = rsEmployees.Fields.Item("Notes")
  70.         Me.txtState = rsEmployees.Fields.Item("State/Province")
  71.         Me.txtWebPage = rsEmployees.Fields.Item("Web Page")
  72.         Me.txtZip = rsEmployees.Fields.Item("Zip/Postal Code")
  73.     End If
  74.  
  75.     Exit Sub
  76.  
  77. DbError:
  78.     MsgBox "There was an error retrieving information " & _
  79.         "from the database. " _
  80.         & Err.Number & ", " & Err.Description
  81. End Sub
Mar 13 '10 #1
1 2398
NeoPa
32,556 Expert Mod 16PB
I suggest you have a look at one or two of the existing forms in the database.

Managing data with forms is supposed to be a whole lot simpler than you have it. Look particularly at the RecordSource property of the form, and the ControlSource property of the controls that reflect each field.

Let us know if further guidance is neede, though I expect once you see how it should be you'll find it all a whole lot easier.
Mar 15 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: vighnesh | last post by:
Hi All I am dealing a project in ASP.NET in which I have to establish a connection to SQL Server 2000 database,where the database was located on a remote system. For this I have used...
5
by: Mitya Mitriev | last post by:
Hi I created ASP.NET 2.0 web application that uses SQL Server 2000 database and it works perfectly when website and Sql server were on local machine. Then I installed application on production...
0
by: IBB | last post by:
Hi W'e are using a vb sql database , and have set a timer for 45 seconds . this timer is to call a stored procedure , to update the information in database . This error which flashes is "...
4
by: Noy B | last post by:
Hi, I have developed a small application that is using a MSAccess DB. the problem is that it was developed on a machine where the application and the DB are both located. now it needs to be...
8
by: BD | last post by:
I am developing C# win form app to work with remote database on SQL Server 2005. Problem scenario is as follows: 1. a form is open that has downloaded dataset to local cache 2. computer is...
1
by: ladybug via AccessMonster.com | last post by:
I am trying to change the data in a text field in a table. I can change this field in other entries, but one specific one I receive this error: The search key was not found in any record. (Error...
0
by: aboutjav.com | last post by:
Hi, I need some help. I am getting this error after I complete the asp.net register control and click on the continue button. It crashed when it tries to get it calls this Profile property ...
5
by: Cirene | last post by:
I just deployed my new ASP.NET (3.5 FW) site to the hosting company I'm using, webhost4life. NOTE: I HAVE deployed other SQL Server sites to the same account with no issues. Now I'm getting...
17
by: mandanarchi | last post by:
Access 2003; PC with Windows XP; SBS 2003 I tried searching the forums but it came up with a blank page. I searched Google and found an answer; but the 'problem' doesn't relate to our situation!...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.