Short answer: ChatGPT can't open a connection to SQL Server by itself. Give it one
through an app that only runs read-only SQL. With AI2SQL you add the database once with a
db_datareader login, install the AI2SQL app in ChatGPT,
and sign in. The same steps work for Azure SQL Database and Amazon RDS for SQL Server.
Step 1: a read-only SQL Server login
Enforce read-only in SQL Server itself, so a write fails even if every other layer missed it:
-- SQL Server / RDS
CREATE LOGIN chatgpt_ro WITH PASSWORD = 'a-long-random-Passw0rd!';
USE AppDb;
CREATE USER chatgpt_ro FOR LOGIN chatgpt_ro;
ALTER ROLE db_datareader ADD MEMBER chatgpt_ro;
-- Azure SQL Database (contained user, run in the database)
CREATE USER chatgpt_ro WITH PASSWORD = 'a-long-random-Passw0rd!';
ALTER ROLE db_datareader ADD MEMBER chatgpt_ro;
To keep some tables out of reach, skip db_datareader and grant SELECT on
chosen schemas instead, for example GRANT SELECT ON SCHEMA::sales TO chatgpt_ro;.
Step 2: add the database to AI2SQL
Sign in at builder.ai2sql.io, open Connections, pick
SQL Server and enter the host, port (usually 1433), database and the
chatgpt_ro login. If SQL Server runs on your laptop, as SQL Server Express or a named
instance, or inside a private network, use the desktop connector instead.
Step 3: install AI2SQL in ChatGPT
- Open the AI2SQL app in the ChatGPT plugin directory and add it.
- ChatGPT opens AI2SQL. Sign in with the account that holds the SQL Server connection and press Allow.
- In a new chat, type @AI2SQL so ChatGPT uses the app for your question.
Prefer to add it by hand? Turn on developer mode in ChatGPT's connector settings and create a
connector with the URL https://builder.ai2sql.io/api/chatgpt-mcp and OAuth authentication.
Step 4: ask a question
Try "@AI2SQL describe my SQL Server database, then show the 10 customers with the most orders
this quarter." ChatGPT reads the real schema with describe_schema, writes T-SQL
(TOP, DATEADD, square-bracket names) and runs it with
run_query. Ask ChatGPT to show the SQL it ran if you want to check it.
What keeps it safe
- Database level: the
chatgpt_rologin can only read. - Gateway level: one
SELECTorWITHstatement per call; writes,EXEC, DDL and functions such asxp_cmdshell,OPENROWSETandWAITFORare rejected before they reach SQL Server. - Limits: results are capped at 1,000 rows.
- No shared secrets: ChatGPT holds a revocable sign-in token, never the SQL Server password.
- Audit: every call appears in Agent activity with the SQL, the database and the result, including blocked attempts.
Common SQL Server snags
- Login failed for user: SQL Server may be set to Windows authentication only. Turn on mixed mode (SQL Server and Windows authentication) and restart the service.
- Cannot reach the server: open port 1433 for AI2SQL, or on Azure add a firewall rule. For anything on a private network, the desktop connector avoids opening ports.
- Empty schema: the login has no
SELECTon the tables you expect. Check the role membership in the right database.
The same connection also works from Claude and Cursor. For PostgreSQL and MySQL, see ChatGPT + PostgreSQL and ChatGPT + MySQL.