Skip to content
Auscultby NBIT
EN
Free diagnostic

Access error reference

Access error 3151: ODBC connection failed (DSN, driver, server)

The Access database works on its author's PC but not on another: the ODBC connection fails before the first record. Most often, the data source or the driver does not exist on that PC.

The message

Microsoft Visual Basic box: “Run-time error '3151': ODBC--connection to '{SQL Server} SRV-SQL01' failed.”
The real error box, captured in Access for Microsoft 365, in English: a pass-through query targets the SQL server “SRV-SQL01”, which cannot be reached.

ODBC--connection to '…' failed.

Access for Microsoft 365, English; in quotes, the driver and the server

On a French Access: « ODBC -- Échec de la connexion à « … ». »

Microsoft describes 3151 as the ODBC connection to the specified database or table not being made, for example when the network is not available.

Where it shows up

When opening a linked table or anything based on it, at start-up if a start-up form reads a server table, or in code that opens a connection (OpenDatabase, RefreshLink).

Common causes

  • the DSN does not exist on this PC: linked tables keep the name of a data source created on the author's PC;
  • the driver is not installed, or not the right version: 64-bit Office needs a 64-bit driver and DSN, 32-bit Office a 32-bit DSN;
  • the server changed: new name, new address, renamed database, firewall;
  • the account is refused: SQL login changed, or a Windows account with no rights on the database.

How to reproduce and check it

  1. Note the name quoted in the message, then look for it in the PC's ODBC Data Source Administrator.
  2. Check the version: on 64-bit Windows, the 32-bit administrator is C:\Windows\SysWOW64\odbcad32.exe, the 64-bit one is in System32.
  3. Test the connection from the ODBC administrator: if it fails there too, the problem is the PC or the server, not the Access database.
  4. In the Immediate window (Ctrl+G), type ? CurrentDb.TableDefs("dbo_Customers").Connect to read a linked table's connection string.

How to fix it

Create the missing DSN with the same name and the same bitness as Office, or remove the DSN dependency by linking the tables with a full connection string.

For example, for each linked table: tdf.Connect = "ODBC;Driver={ODBC Driver 17 for SQL Server};Server=SRV01;Database=Sales;Trusted_Connection=Yes;", then tdf.RefreshLink. Adapt the driver to the PC and the server name.

What Auscult reports

Auscult only runs the database on a copy and does not connect to servers: their data cannot be copied, and the analysis must not change it. The report names the source (“server database (ODBC)”, with its DSN when the database has one) and the linked tables that read it.

So it does not test the connection itself. It does show what depends on that server, and what could not be tried without it.

The Access error reference, code by code

Frequently asked questions

Why does the database work for a colleague and not for me?

The DSN and the driver are installed PC by PC. Your colleague has the data source; your PC does not, or has it in the other bitness (32 or 64-bit).

Do I have to keep a DSN?

No. A full connection string in the linked tables avoids installing a DSN on every PC; the driver still has to be installed.

Where are the other errors in your application hiding?

The diagnostic runs on your computer, on a copy of the application, without sending the data in your tables. The health grade and the summary are free.