Results 1 to 11 of 11
  1. #1
    Thomasso is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250

    ODBC call failed (runtime 3146) on another PC

    Hello,



    I've been developing an Access app for a while and I'm finally at the stage of deploying and testing on multiple devices. Front end is MS Access (obviously) and back and is Microsoft SQL Server 2019.

    I use DSNless connection of linked tables, using this code:

    Code:
    Public Const CONNECTION_STRING_DAO = "ODBC;Driver={SQL Server Native Client 11.0};Server=SRV01;Database=DATYS_TESTING;Trusted_Connection=yes;"
    
    Public Sub LinkSQLTables()
    On Error GoTo ErrHandler
    
        Dim td As TableDef
        Dim rs As Recordset
        
        
        For Each td In CurrentDb.TableDefs
        
            If td.Name Like "v_*" Or td.Name Like "vDE_*" Or td.Name Like "v2_*" Then
                CurrentDb.TableDefs.Delete td.Name
            End If
            
        Next
        
        Set rs = CurrentDb.OpenRecordset("SELECT * FROM SQL_Links", dbOpenSnapshot)
        
        Do While Not (rs.BOF Or rs.EOF)
        
            Set td = CurrentDb.CreateTableDef(rs!LinkName, dbAttachSavePWD, rs!LinkName, CONNECTION_STRING_DAO)
            CurrentDb.TableDefs.Append td
    
            CurrentDb.Execute "CREATE INDEX " & rs("LinkName") & "_PK ON " & rs("LinkName") & " (" & rs("PrimaryKeyField") & ") WITH PRIMARY"
            
            rs.MoveNext
        
        Loop
        
        rs.Close
        Set rs = Nothing
            
    Exit Sub
    ErrHandler:
    
        MsgBox "Během pokusu o spojení s databází nastala chyba. Aplikace bude ukončena." & vbNewLine & vbNewLine & _
                "Číslo chyby: " & Err.Number & vbNewLine & _
                "Popis chyby: " & Err.Description, vbCritical + vbOKOnly, "Chyba"
                
        rs.Close
        Set rs = Nothing
                
        Application.Quit
        
    End Sub
    This works just fine using my developer PC.

    For deployment purposes, I installed Access Runtime on another PC within the same network, and saved the DB as ACCDE file. I am perfectly able to run this on my dev PC as well.

    However, I get the "ODBC call failed runtime 3146" while executing the "LinkSQLTables" procedure (using the other PC).

    At the same, I can open SQL Server Management Studio on the other PC and I'm perfectly able to connect to the database and browse through it, using Windows credentials, same as in the connection string.

    Everything is in the same Active Directory environment, both PCs are Windows 10, I am logged with the same credential and it's the exact same ACCDE file. Both PCs can access the SQL server using the Management Studio.

    Can you think of any reason why this might be happening?

    Thank you very much.
    Tomas

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Are the references the same?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Thomasso is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    What do you mean?

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Quote Originally Posted by Thomasso View Post
    What do you mean?
    I mean that there might be a reference missing on the errant PC?
    Compare that to yours.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Thomasso is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    Is this relevant for MS Access Runtime? I can't choose any references, I can just run a finished ACCDE application, or is that not the case?

  6. #6
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    What ODBC driver is installed on the runtime machine?

    If it doesn't have SQL Server Native Client 11.0 installed, (Very old by the way I would recommend updating to Ver 17 at least, on all machines) it won't be able to connect.
    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 ↓↓

  7. #7
    Thomasso is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    Honestly I didn't think of this, figured it would be installed by default. If I install Ver 18 (by searching, this seems to be the newest one), do I need to update the connection string as well, or is there backwards compatibility?

    What if there is a new driver available in the future? Will I need to also update the connection string and push new front end version to the users?

    Thank you!

  8. #8
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Yes to both your questions, the connection string must match the installed driver. One way to do it is to have a custom system table in the front end (just use the prefix usys like in usysSettings) in which you store the connection string instead of hard-coding it as a constant in VBA. And have you considered using TableDef.RefreshLink method in your LinkSQLTables() procedure instead of deleting and recreating?
    https://learn.microsoft.com/en-us/of...ink-method-dao

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  9. #9
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    @Gicu has provided the answers, but to clarify they aren't backwards compatible, they are specific. Version 18 is the latest.

    You can go one stage further if you need to, we have routines that search the registry and then set the driver/connection string for the latest one installed, but it not trivial to set up as you need to keep the lists up to date and have a way of updating them...
    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 ↓↓

  10. #10
    Thomasso is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    Thank you guys, indeed it helped to change the connection string to Driver 17 and to make sure it is installed on that PC. I will look into the other suggestions. Would it be quicker to use TableDef.RefreshLink? Because the current process is kind of slow.

  11. #11
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    I'm pretty sure the refresh works quicker from memory.

    If you go into the linked table manager and click refresh links(after selecting all the tables) it it pretty rapid, as it won't be re-writing all the table info (Remote name, connection string, local name etc. etc.)
    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. ODBC - call failed
    By nggman in forum Queries
    Replies: 2
    Last Post: 10-30-2017, 07:16 AM
  2. ODBC Call Failed
    By jerem in forum SQL Server
    Replies: 2
    Last Post: 07-12-2016, 08:53 PM
  3. Replies: 1
    Last Post: 03-02-2015, 09:44 AM
  4. "Run Time Error 3146, ODBC call failed" :(
    By selvakumar.arc in forum Access
    Replies: 0
    Last Post: 12-04-2014, 01:57 PM
  5. ODBC -- call failed. | Oracle ODBC
    By drdexter33 in forum Access
    Replies: 1
    Last Post: 04-03-2010, 09:32 PM

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