Connect ChatGPT to SQL Server, read-only

Add your SQL Server database to AI2SQL, install the AI2SQL app in ChatGPT and sign in. ChatGPT can then answer questions from your SQL Server data with real T-SQL, while writes are blocked and your password never leaves AI2SQL.

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

  1. Open the AI2SQL app in the ChatGPT plugin directory and add it.
  2. ChatGPT opens AI2SQL. Sign in with the account that holds the SQL Server connection and press Allow.
  3. 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

Common SQL Server snags

The same connection also works from Claude and Cursor. For PostgreSQL and MySQL, see ChatGPT + PostgreSQL and ChatGPT + MySQL.

Frequently asked

Can ChatGPT connect to Microsoft SQL Server? +

Yes. Install the AI2SQL app in ChatGPT and sign in. Once a SQL Server connection is added in AI2SQL, ChatGPT can read its schema and run read-only T-SQL on it. ChatGPT never sees the SQL Server password.

Can ChatGPT change data in SQL Server? +

Not through AI2SQL. run_query accepts one SELECT or WITH statement per call and rejects INSERT, UPDATE, DELETE, MERGE, EXEC and DDL before they reach SQL Server. Use a login that is only in db_datareader so the database refuses writes as well.

Does it work with Azure SQL Database and Amazon RDS for SQL Server? +

Yes, as long as AI2SQL can reach the server over the network. On Azure SQL Database, create a contained database user with a password and allow the connection in the server firewall. A SQL Server on your laptop or office network needs the AI2SQL desktop connector.

What about SQL Server Express or a named instance like .\SQLEXPRESS? +

A local or named instance is not reachable from the internet, so use the AI2SQL desktop connector on a machine that can reach it. Enable TCP/IP in SQL Server Configuration Manager and use SQL Server authentication for the read-only login.

Do I need ChatGPT developer mode? +

No. AI2SQL is in the ChatGPT plugin directory. Developer mode is only needed if you want to add the server URL by hand.

Can I try it before connecting SQL Server? +

Yes. Ask: Use AI2SQL to show the top 5 customers by revenue in demo_shop. demo_shop is a shared sample store with fake data and works on every plan. Running queries on your own database needs Pro or Team, which start with a 7-day trial.

Ask ChatGPT about your SQL Server data

Connect SQL Server, add the AI2SQL app in ChatGPT, sign in. Read-only and logged from the first query.

Connect SQL Server free →

Related guides