473,408 Members | 1,734 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,408 software developers and data experts.

Reconnect Code Problem

The following code which automatically reconnects a database backend
by Peter Vukovic works well except for one minor glitch. On the first
opening of the frontend, a message box appears saying that the backend
cannot be found. If the frontend is closed and then reopened the
backend will connect OK. It will then remain connected for any
subsequent opening. The problem only appears on the first opening of
the frontend after the path is changed. Any help on why this is
happening would be appreciated.

Function Reconnect()
On Error Resume Next

'************************************************* *************
'* START YOUR APPLICATION (MACRO: AUTOEXEC) WITH THIS FUNCTION
'* AND THIS PROGRAM WILL CHANGE THE CONNECTIONS AUTOMATICALLY
'* WHEN THE 'DATA.MDB' AND THE 'PRG.MDB'
'* ARE IN THE SAME DIRECTORY!!!
'* PROGRAMMING BY PETER VUKOVIC, Germany
'* 10*********@compuserve.com
'* ************************************************** **********
Dim db As Database, Source As String, path As String
Dim dbsource As String, i As Integer, j As Integer

Set db = DBEngine.Workspaces(0).Databases(0)
'************************************************* ************
'* RECOGNIZE THE PATH *
'************************************************* ************

For i = Len(db.Name) To 1 Step -1
If Mid(db.Name, i, 1) = Chr(92) Then
path = Mid(db.Name, 1, i)
'MsgBox (path)
Exit For
End If
Next
'************************************************* ************
'* CHANGE THE PATH AND CONNECT AGAIN *
'************************************************* ************

For i = 0 To db.TableDefs.Count - 1
If db.TableDefs(i).Connect <> " " Then
Source = Mid(db.TableDefs(i).Connect, 11)
'Debug.Print source
For j = Len(Source) To 1 Step -1
If Mid(Source, j, 1) = Chr(92) Then
dbsource = Mid(Source, j + 1, Len(Source))
Source = Mid(Source, 1, j)
If Source <> path Then
db.TableDefs(i).Connect = ";Database=" + path
+ dbsource
db.TableDefs(i).RefreshLink
'Debug.Print ";Database=" + path + dbsource
End If
Exit For
End If
Next
End If
Next
End Function
Nov 13 '05 #1
1 1598
Just a quick comment. Sorry if you're already doing this, but have
you considered storing the current back-end path in a table and using
that to initialize on startup?

On 15 Sep 2004 14:49:36 -0700, cq*******@volcanomail.com (Wayne
Aprato) wrote:
The following code which automatically reconnects a database backend
by Peter Vukovic works well except for one minor glitch. On the first
opening of the frontend, a message box appears saying that the backend
cannot be found. If the frontend is closed and then reopened the
backend will connect OK. It will then remain connected for any
subsequent opening. The problem only appears on the first opening of
the frontend after the path is changed. Any help on why this is
happening would be appreciated.

Function Reconnect()
On Error Resume Next

'************************************************ **************
'* START YOUR APPLICATION (MACRO: AUTOEXEC) WITH THIS FUNCTION
'* AND THIS PROGRAM WILL CHANGE THE CONNECTIONS AUTOMATICALLY
'* WHEN THE 'DATA.MDB' AND THE 'PRG.MDB'
'* ARE IN THE SAME DIRECTORY!!!
'* PROGRAMMING BY PETER VUKOVIC, Germany
'* 10*********@compuserve.com
'* ************************************************** **********
Dim db As Database, Source As String, path As String
Dim dbsource As String, i As Integer, j As Integer

Set db = DBEngine.Workspaces(0).Databases(0)
'************************************************ *************
'* RECOGNIZE THE PATH *
'************************************************ *************

For i = Len(db.Name) To 1 Step -1
If Mid(db.Name, i, 1) = Chr(92) Then
path = Mid(db.Name, 1, i)
'MsgBox (path)
Exit For
End If
Next
'************************************************ *************
'* CHANGE THE PATH AND CONNECT AGAIN *
'************************************************ *************

For i = 0 To db.TableDefs.Count - 1
If db.TableDefs(i).Connect <> " " Then
Source = Mid(db.TableDefs(i).Connect, 11)
'Debug.Print source
For j = Len(Source) To 1 Step -1
If Mid(Source, j, 1) = Chr(92) Then
dbsource = Mid(Source, j + 1, Len(Source))
Source = Mid(Source, 1, j)
If Source <> path Then
db.TableDefs(i).Connect = ";Database=" + path
+ dbsource
db.TableDefs(i).RefreshLink
'Debug.Print ";Database=" + path + dbsource
End If
Exit For
End If
Next
End If
Next
End Function


Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steve | last post by:
I need to introduce a JMS reconnect feature into an existing application. Basically, the application is a simple consumer of messages from a JMS topic. My requirement is to have the application...
4
by: MS | last post by:
Access 97 I have an Access FE that reconnects "automatically" regardless of whether the FE or BE have been moved to another folder. To achieve this, I have used Peter Vukovic's ( ...
10
by: lauren quantrell | last post by:
I'm using Access 2K's built-in connection method (FILE>CONNECTION) with the Windows NT Integrated Security login option to establish my server connection. Is there a way in code to refresh or...
1
by: John | last post by:
When I ping my server over the internet connection and the server isn't responding due to the connection not working properly is it possible in .Net to reconnect the connection if the ping is...
0
by: mkahn | last post by:
Fater leaving my computer for a few minutes. I tried to continue working with the page am on. Seems to be that after my connection timed out, am not able to reconnect to the data base getting the...
9
by: Big Daddy | last post by:
We have a problem where the session is getting abandoned for no apparent reason. It's not timing out. We save some important data in the Session object. The user will click on something, causing a...
1
by: terron | last post by:
I'm trying to make something that once it is disconnected will automatically try to reconnect. I'll add some more features in later so it doesn't hammer the server but right now I just want to keep...
3
by: joes.mailing.lists | last post by:
Hi, I'm working a web application using comet (Orbited) for real-time status updates and messaging. The messaging system works great, but I've noticed that if I disconnect my laptop internet...
0
by: Dreea | last post by:
Hello everybody I am working on a client application that connects to a C# server using the Socket class. I am trying to handle the case in which the server goes offline, and I would like the...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.