Access FE - SQL Server BE - relink tables (1 Viewer)

JohnPapa

Registered User.
Local time
Today, 14:39
Joined
Aug 15, 2010
Messages
954
I have an Access FE and an SQL Server BE and I use linked tables.

I would like to relink the existing tables and also be able to link to a copy of the SQL Server BE, situated elsewhere.
 

JohnPapa

Registered User.
Local time
Today, 14:39
Joined
Aug 15, 2010
Messages
954
I can get the Connection string for a table by using

Code:
strDum = CurrentDb.TableDefs(TableName).Connect

and I guess would need to store this, for future use
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:39
Joined
Oct 29, 2018
Messages
21,473
You might want to look into DSN-less connections.
 

sonic8

AWF VIP
Local time
Today, 13:39
Joined
Oct 27, 2015
Messages
998
I would like to relink the existing tables and also be able to link to a copy of the SQL Server BE, situated elsewhere.
Sorry for being stand-off-ish, but please do some research on this topic first. It has been discussed and solved with publicly available solutions a million times.

If you got specific problems applying a solution you are very welcome for help here.
 

JohnPapa

Registered User.
Local time
Today, 14:39
Joined
Aug 15, 2010
Messages
954
I came up with something like the following

Code:
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
 
'Get Connection string
Dim strConString As String
strConString = GetLinkedDBName("dbo_tblBuilding")


'Store Connection string
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "dbo_tblSerial", CurrentProject.Connection, adOpenKeyset, adLockPessimistic
rst.MoveFirst
rst!strConnectionString = strConString
rst.Update


' Loop through all tables
Set dbs = CurrentDb
For Each tdf In dbs.TableDefs
  
    ' Check if it is a linked table
    If Len(tdf.Connect) > 0 Then
        
        'For linked table check if Connection string is different
        If tdf.Connect <> strConString Then
        
            'Assign proper Connection string
            tdf.Connect = strConString
            On Error Resume Next
            tdf.RefreshLink
        End If
    End If
 
Next tdf

If I msgbox the connection string, the DB Password appears. However, if I hover over the linked table name the DB Password does not appear.
 

Minty

AWF VIP
Local time
Today, 12:39
Joined
Jul 26, 2013
Messages
10,371
Short answer yes. That's the point!

ODBC or OLEDB - are just connection methods.

Read here
 

JohnPapa

Registered User.
Local time
Today, 14:39
Joined
Aug 15, 2010
Messages
954
Short answer yes. That's the point!

ODBC or OLEDB - are just connection methods.

Read here
Thanks. FYI, in the article you refer the following do not work
1691743973962.png

1691743983643.png
 

JohnPapa

Registered User.
Local time
Today, 14:39
Joined
Aug 15, 2010
Messages
954
Also can you please clarify what happens to the linked file link. Is it deleted? Does it remain? Is it used in any way?
 

Minty

AWF VIP
Local time
Today, 12:39
Joined
Jul 26, 2013
Messages
10,371

sonic8

AWF VIP
Local time
Today, 13:39
Joined
Oct 27, 2015
Messages
998
If I msgbox the connection string, the DB Password appears. However, if I hover over the linked table name the DB Password does not appear.
This is deliberate.
If you display a string variable in a MsgBox, it will of course show the password if it is included in the string.
If you hover over a linked table, the tooltip deliberately doesn't include the password to not show it to people not supposed to see it. Recently there was a change in Access (I don't know if intentional or accidental) that would include the password in the tooltip. There were complaints about this change and Microsoft rolled back the change to exclude the password from the tooltip again.

While I do not agree with this security by obscurity approach, I understand the reasoning.
 

JohnPapa

Registered User.
Local time
Today, 14:39
Joined
Aug 15, 2010
Messages
954
It is a 15-year-old thread to be fair.

The best connection strings site is here:

And Doug Steele's stuff has also moved to here:
Am I correct in assuming that to use the DSNless links (DB password not showing in link) I need a Trusted connection?
 

JohnPapa

Registered User.
Local time
Today, 14:39
Joined
Aug 15, 2010
Messages
954
It is a 15-year-old thread to be fair.

The best connection strings site is here:

And Doug Steele's stuff has also moved to here:
I ran the DSNless code.

In my case Trusted_connection=No

and commented out (as stated in the comments) the following line

Code:
' Unfortunately, I'm current unable to test this code,
' but I've been told trying this line of code is failing for most people...
' If it doesn't work for you, just leave it out.


    tdfCurrent.Attributes = typNewTables(intLoop).Attributes   'I commented out this line

It ran without an error, but I do not see anything different from before.
 

sonic8

AWF VIP
Local time
Today, 13:39
Joined
Oct 27, 2015
Messages
998
Am I correct in assuming that to use the DSNless links (DB password not showing in link) I need a Trusted connection?
No. You can also execute a temporary Pass-Through-Query with the password in the connection string and immediately afterwards link the tables to the very same connection without the password in the connections string.
You would then also need to run that Pass-Through-Query on startup of your application to establish the connection.
 

Users who are viewing this thread

Top Bottom