473,789 Members | 2,537 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 GetConnectStrin g(Optional strTableName As String, Optional
BackupFileFullN ame 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 BackupFileFullN ame <> "" Then 'PW PROTECTED DB WAS PASSED
Set dbs = DBEngine.Worksp aces(0).OpenDat abase(BackupFil eFullName, False,
False, "MS Access;PWD=love ya")
Else
Set dbs = CurrentDb
End If

'THE FOLLOWING GETS THE LAST RECORD TO VERIFY PW PROTECTED DB WAS OPENED
Set rsTEST = dbs.OpenRecords et(strTableName , dbOpenDynaset)
If rsTEST.RecordCo unt > 0 Then
rsTEST.MoveLast
MsgBox rsTEST("BUILDIN G_NO")
End If

'Extract connect string
If Len(strTableNam e) > 0 Then
Set tdf = dbs.TableDefs(s trTableName)
Else
For Each tdf In dbs.TableDefs
If IsUserTable(tdf ) And Len(tdf.Connect ) > 0 Then
If left(tdf.Connec t, 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.OpenRecords et
lngRecordCount = rst.RecordCount

'Parse the connect string to return to calling procedure/object
If Err = 0 Then
If Len(strTemp) = 0 Then
GetConnectStrin g = "<None>"
Else
If blFullString = True Then
GetConnectStrin g = strTemp
Else
GetConnectStrin g = Mid(strTemp, InStr(1, strTemp, ";DATABASE= ") + Len
(";DATABASE= "))
End If
End If
Else
Err.Clear
GetConnectStrin g = "<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 5363
robert demo via AccessMonster.c om 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 GetConnectStrin g(Optional strTableName As String, Optional BackupFileFullN ame 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 BackupFileFullN ame <> "" Then 'PW PROTECTED DB WAS PASSED
Set dbs = DBEngine.Worksp aces(0).OpenDat abase(BackupFil eFullName, False, False, "MS Access;PWD=love ya")
Else
Set dbs = CurrentDb
End If

'THE FOLLOWING GETS THE LAST RECORD TO VERIFY PW PROTECTED DB WAS OPENED Set rsTEST = dbs.OpenRecords et(strTableName , dbOpenDynaset)
If rsTEST.RecordCo unt > 0 Then
rsTEST.MoveLast
MsgBox rsTEST("BUILDIN G_NO")
End If

'Extract connect string
If Len(strTableNam e) > 0 Then
Set tdf = dbs.TableDefs(s trTableName)
Else
For Each tdf In dbs.TableDefs
If IsUserTable(tdf ) And Len(tdf.Connect ) > 0 Then
If left(tdf.Connec t, 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.OpenRecords et
lngRecordCount = rst.RecordCount

'Parse the connect string to return to calling procedure/object
If Err = 0 Then
If Len(strTemp) = 0 Then
GetConnectStrin g = "<None>"
Else
If blFullString = True Then
GetConnectStrin g = strTemp
Else
GetConnectStrin g = Mid(strTemp, InStr(1, strTemp, ";DATABASE= ") + Len
(";DATABASE= "))
End If
End If
Else
Err.Clear
GetConnectStrin g = "<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]", "MSysObject s", "[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
4749
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, but once per week, the oracle server is brought down for backup. At that time, I get an error that looks like I have the wrong credentials for the database. For every subsequent attempt to run the hourly process, I am getting a broken pipe error,...
1
6490
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 any suggestions! Thanks! The connection is already Open (state=Open). Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where...
7
7825
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 only log on I have created. On some PCs I am having a problem. The code runs and then displays a Log On box with the Trusted Connection checked and the users NT logon displayed. What causes this? Is there a way to correct it? Thanks! Kathy
5
8749
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. I have gone back and forth between using a DSN file and a DSN-less connection string and I have found the following issue. When I utilize the DSN file to create the link, there is a step where it asks me to identify a unique key for the file. If I...
0
1585
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 2000) as follows USERS TABLE
12
2880
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 text into a stream in order to be able to use DataSetOutcomes1.ReadXML(MyStream). Thanks in advance, James
0
3742
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 exception is raised from a Web .Net app while exactly the same code works fine in Windows .Net app. That makes me thinking the issue somehow is related to security context. Anyway I do not know how to solve the problem, and any help is...
5
7356
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 when having ODBC linked tables, JET queries on linked tables and pass-through queries? Thanks,
0
1288
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 checked it's properties to get the connection string, which is: ODBC;DSN=D573;SERVER=D573;;TABLE=KHAMELEON.HM_COMMISSION_EXTRACT So I created my macro, used the TransferDatabase method, set the Database Name to the above string, the source to...
0
10193
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9978
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9015
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7524
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6755
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4087
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.