SQL ServerConnector

How to Connect AI to a Local SQL Server Database

You typed localhost into a cloud SQL tool and the connection failed. It was never going to work, and the reason has nothing to do with your credentials.

Aug 11, 20269 min

Why the connection fails

localhost is not an address — it is a word meaning "this machine". When a cloud service dials localhost, it reaches its own server. Your database is not there.

The same is true of every private address:

  • 127.0.0.1 — the loopback of whichever machine is asking
  • 192.168.x.x, 10.x.x.x, 172.16–31.x.x — private ranges, not routable from the internet
  • A hostname like SQLPROD01 that only your internal DNS can resolve

This is why the credentials never matter: the request never reaches a database at all.

The three ways out

1. Expose the database to the internet

Port forwarding on port 1433 with a public IP. It works, and it is the option most security teams will refuse. A SQL Server port open to the internet gets scanned within hours.

2. A tunnel

An SSH tunnel or a VPN moves the boundary rather than removing it. Workable if you already run that infrastructure, and a real setup burden if you do not — and it still ends with the cloud service holding a live route into your network.

3. Run something local that connects outward

The direction reverses: instead of the cloud reaching into your network, a small program next to the database opens an outbound connection. No inbound port, no firewall change, no tunnel. This is how the AI2SQL Connector works.

Setting it up

  1. Download the Connector for your platform from ai2sql.io/connector. One binary, no installer.
  2. Run it. It opens a page on 127.0.0.1:5533. On the first launch Windows SmartScreen or macOS Gatekeeper will interrupt once, because the builds are not code-signed yet; the download page has the exact steps.
  3. Sign in with your existing AI2SQL account. Queries count against the plan you already have.
  4. Enter your database details — host, port, user, password. They are stored on your machine.
  5. Load the schema. Your real table and column names become available to the assistant, so generated SQL fits your database instead of a guess.

SQL Server specifics

  • Named instances. SQLPROD01\SQLEXPRESS needs either the instance name or the port it is listening on. The SQL Browser service resolves the name; if it is off, use the port.
  • TCP/IP disabled. Express installations frequently ship with TCP/IP off. Enable it in SQL Server Configuration Manager, then restart the service.
  • Windows Authentication. If the connector runs as a different user, create a SQL login for it rather than fighting the domain.
  • Use a read-only user. The connector enforces read-only queries, but a read-only login means the database enforces it too.

What leaves your machine

The schema — table names, column names and types — and the question you ask. Query results are read locally and stay there. That distinction is usually the one that matters in a review: schema is metadata, rows are data.

If the answer for your organisation is "not even the schema", then no cloud AI tool of any kind is appropriate, and that is a legitimate conclusion to reach quickly.

Once connected

The useful part is that queries are written against your actual tables. From there the same three jobs apply: understanding a query somebody else wrote, fixing one that errors, and speeding one up.

Working with a local database?

The AI2SQL Connector runs on your machine and connects from your side of the firewall. Windows, macOS and Linux.

Get Started Free

No credit card required