Results 1 to 6 of 6
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2016
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    DSNLess Link Azure Table To Access

    I am wanting to DSNLess link multiple azure sql tables to my access database. This is the code I have
    Code:
    Public Function AttachDSNLessTable(table)
        On Error GoTo AttachDSNLessTable_Err
        Dim td As TableDef
        Dim stConnect As String
        
        'Alter these variables to change any settings
        Dim stLocalTableName As String, stRemoteTableName As String, stServer As String, stDatabase As String
        Dim stUsername As String, stPassword As String, S As String, pkfield As String
        localTable = Replace(table, ".", "")
            'What table name will be in access
        stLocalTableName = "Azure_" & localTable
            'What table name is in SQL Server
        stRemoteTableName = table
        pkfield = "ID"
            'Server name
        stServer = "server"
            'Database
        stDatabase = "database"
            'User
        stUsername = "user"
            'Password
        stPassword = "password"
        
        
        For Each td In CurrentDb.TableDefs
            If td.Name = stLocalTableName Then
                CurrentDb.TableDefs.Delete stLocalTableName
            End If
        Next
          
        If Len(stUsername) = 0 Then
            '//Use trusted authentication if stUsername is not supplied.
            stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";Trusted_Connection=Yes"
        Else
            '//WARNING: This will save the username and the password with the linked table information.
            stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";UID=" & stUsername & ";PWD=" & stPassword
        End If
        Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
        CurrentDb.TableDefs.Append td
        AttachDSNLessTable = True
            
        Exit Function
    
    
    AttachDSNLessTable_Err:
        
        AttachDSNLessTable = False
        MsgBox "AttachDSNLessTable encountered an unexpected error: " & Err.Description
    
    
    End Function
    This works fine for my inhouse SQL Server - but i get the error
    Code:
    AttachDSNLessTable encountered an unexpected error: ODBC--call failed
    What am I missing here?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What does the finished string look like? I connect to Azure tables all the time, an example of the finished string:

    ODBC;DRIVER=ODBC Driver 17 for SQL Server;SERVER=tcp:server.domain.com,1433;UID=abc;PWD=xyz;APP=Microsoft Office;DATABASE=Lease;

    Also make sure the user has permissions of course, and their IP address is whitelisted if that feature is being used.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2016
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by pbaldy View Post
    What does the finished string look like? I connect to Azure tables all the time, an example of the finished string:

    ODBC;DRIVER=ODBC Driver 17 for SQL Server;SERVER=tcp:server.domain.com,1433;UID=abc;PWD=xyz;APP=Microsoft Office;DATABASE=Lease;

    Also make sure the user has permissions of course, and their IP address is whitelisted if that feature is being used.
    IP is whitelisted and user has perms. I have verified by connecting via SSMS

    The connection string looks like this

    ODBC;DRIVER=SQL Server;SERVER=server;DATABASE=TestDb;UID=user;PWD= pass

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    I would say you would need to use a newer driver with Azure instead of the legacy driver you are currently trying. MS says here it wants Microsoft ODBC Driver for SQL Server version 17.2.0.1 or later:
    https://learn.microsoft.com/en-us/az...nection-string
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    "server" is an address, not just the name of a server like would work on a LAN?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    + 1 for both pbaldy and Gicu comments we use Azure SQL all the time.
    If you can connect in SSMS check it's connection properties. They should be very similar to the ones required in Access.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Please reply to this thread with any new information or opinions.

Similar Threads

  1. MS Access can not remember an Azure SQL login
    By EZ Access Gideon in forum SQL Server
    Replies: 2
    Last Post: 10-18-2020, 10:04 AM
  2. Replies: 2
    Last Post: 09-08-2020, 01:34 AM
  3. access table link to oracle table
    By shah1419 in forum Programming
    Replies: 0
    Last Post: 09-16-2018, 08:13 AM
  4. Access 2010 and SQL Azure
    By drexasaurus in forum SQL Server
    Replies: 2
    Last Post: 09-20-2012, 08:58 AM
  5. Access 2010 to SQL Azure migration
    By Aurelius7 in forum SQL Server
    Replies: 6
    Last Post: 06-18-2012, 10:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums