473,398 Members | 2,404 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,398 software developers and data experts.

Retrieving the connection string for a linked table in PW protected DB

I'm trying to retrieve the connection string for a linked table in a
backend that is password protected. I've modified the code shown below to
temporarily check that the backend has been successfully opened by showing,
via a messagebox, the last record in the table. The connection string
should be provided in the last line shown, but I always get strTemp = "".
I'm certain that the backend has been opened because of the messagebox.

The code works absolutely fine for non-password protected backends.

Here's the snippet (I've added comments in CAPS for code that I've added):

Public Function GetConnectString(Optional strTableName As String, Optional
BackupFileFullName As String, Optional blFullString As Boolean = False) As
String

Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim rst As DAO.Recordset
Dim strTemp As String
Dim lngRecordCount As Long
Dim rsTEST As DAO.Recordset 'TEST RS TO SEE IF PW PROTECTED DB IS OPEN

If BackupFileFullName <> "" Then 'PW PROTECTED DB WAS PASSED
Set dbs = DBEngine.Workspaces(0).OpenDatabase(BackupFileFull Name, False,
False, "MS Access;PWD=loveya")
Else
Set dbs = CurrentDb
End If

'THE FOLLOWING GETS THE LAST RECORD TO VERIFY PW PROTECTED DB WAS OPENED
Set rsTEST = dbs.OpenRecordset(strTableName, dbOpenDynaset)
If rsTEST.RecordCount > 0 Then
rsTEST.MoveLast
MsgBox rsTEST("BUILDING_NO")
End If

'Extract connect string
If Len(strTableName) > 0 Then
Set tdf = dbs.TableDefs(strTableName)
Else
For Each tdf In dbs.TableDefs
If IsUserTable(tdf) And Len(tdf.Connect) > 0 Then
If left(tdf.Connect, 4) <> "ODBC" Then
Exit For
End If
End If
Next tdf
End If
strTemp = tdf.Connect 'THIS IS THE PROBLEM!!!!!

'See if the connect string is valid (an error is generated if invalid)
On Error Resume Next
Set rst = tdf.OpenRecordset
lngRecordCount = rst.RecordCount

'Parse the connect string to return to calling procedure/object
If Err = 0 Then
If Len(strTemp) = 0 Then
GetConnectString = "<None>"
Else
If blFullString = True Then
GetConnectString = strTemp
Else
GetConnectString = Mid(strTemp, InStr(1, strTemp, ";DATABASE=") + Len
(";DATABASE="))
End If
End If
Else
Err.Clear
GetConnectString = "<Not Pointing to Valid File>"
End If
On Error GoTo 0

'Clean up stuff
Set tdf = Nothing
Set dbs = Nothing

--
Message posted via http://www.accessmonster.com
Nov 13 '05 #1
1 5307
robert demo via AccessMonster.com wrote:
I'm trying to retrieve the connection string for a linked table in a
backend that is password protected. I've modified the code shown below to temporarily check that the backend has been successfully opened by showing, via a messagebox, the last record in the table. The connection string should be provided in the last line shown, but I always get strTemp = "". I'm certain that the backend has been opened because of the messagebox.
The code works absolutely fine for non-password protected backends.

Here's the snippet (I've added comments in CAPS for code that I've added):
Public Function GetConnectString(Optional strTableName As String, Optional BackupFileFullName As String, Optional blFullString As Boolean = False) As String

Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim rst As DAO.Recordset
Dim strTemp As String
Dim lngRecordCount As Long
Dim rsTEST As DAO.Recordset 'TEST RS TO SEE IF PW PROTECTED DB IS OPEN
If BackupFileFullName <> "" Then 'PW PROTECTED DB WAS PASSED
Set dbs = DBEngine.Workspaces(0).OpenDatabase(BackupFileFull Name, False, False, "MS Access;PWD=loveya")
Else
Set dbs = CurrentDb
End If

'THE FOLLOWING GETS THE LAST RECORD TO VERIFY PW PROTECTED DB WAS OPENED Set rsTEST = dbs.OpenRecordset(strTableName, dbOpenDynaset)
If rsTEST.RecordCount > 0 Then
rsTEST.MoveLast
MsgBox rsTEST("BUILDING_NO")
End If

'Extract connect string
If Len(strTableName) > 0 Then
Set tdf = dbs.TableDefs(strTableName)
Else
For Each tdf In dbs.TableDefs
If IsUserTable(tdf) And Len(tdf.Connect) > 0 Then
If left(tdf.Connect, 4) <> "ODBC" Then
Exit For
End If
End If
Next tdf
End If
strTemp = tdf.Connect 'THIS IS THE PROBLEM!!!!!

'See if the connect string is valid (an error is generated if invalid) On Error Resume Next
Set rst = tdf.OpenRecordset
lngRecordCount = rst.RecordCount

'Parse the connect string to return to calling procedure/object
If Err = 0 Then
If Len(strTemp) = 0 Then
GetConnectString = "<None>"
Else
If blFullString = True Then
GetConnectString = strTemp
Else
GetConnectString = Mid(strTemp, InStr(1, strTemp, ";DATABASE=") + Len
(";DATABASE="))
End If
End If
Else
Err.Clear
GetConnectString = "<Not Pointing to Valid File>"
End If
On Error GoTo 0

'Clean up stuff
Set tdf = Nothing
Set dbs = Nothing

--
Message posted via http://www.accessmonster.com


Try this...

Dim MyConnString as string
MyConnString = DLookup("[Connect]", "MSysObjects", "[Name]='<< Insert
linked table name here... >>' And [Type]=4")

Hope this helps @:=)

Nov 13 '05 #2

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

Similar topics

0
by: JWM | last post by:
I am trying to implement Oracle connection pooling for the following code, which was written by someone else. Here is my main question -- this java file creates code that is executed every hour,...
1
by: ST | last post by:
This is my other error when I click on Immunoflourescence. I believe this is related to the other error I just posted (Input string was not in a correct format.) Please let me know if you have...
7
by: KathyK | last post by:
Hi and thanks in advance! I have an Access 2000 front end and a SQL Server 2000 back end. When the Access main form opens I run code that logs the user on to the SQL server using the generic read...
5
by: Fred Zuckerman | last post by:
Hello All, After reading in this group about the preference for connecting to a SQL Server using a connection string instead of a DSN file, I have done just that. BUT, I cannot update my data....
0
by: Alistair | last post by:
Hi all, I am creating a database based site that keeps track of books, who has read them and the comments they have. After a little help in M.P.I.asp.DB I managed to create a database (access...
12
by: James Norton-Jones | last post by:
Hi, Am I trying to hold the data of a DataGrid in a label so that when the form is reposted the DataGrid can be repopulated. The problem I am having is that I don't understand how to get the...
0
by: Igor | last post by:
An error "ODBC connection to failed" is raised when I am trying to get data from a table in Microsoft Access (97, or 2000) which is actually a linked table to another table in SQL Server 7 . The...
5
by: Zlatko Matić | last post by:
Hello. In ODBC Data Source Administrator, there is a tab "Connection Pooling" and option "PerfMon" Enable/Disable. Could someone explain the meaning of the option and how it reflects to Access...
0
by: igendreau | last post by:
I'm using the TransferDatabase method to copy down a couple of large tables from an Oracle database so I can report on them locally. I linked to the table I want, opened it in design view and...
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?
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.