How to Configure Vercel AI SDK SQL Server Read Only Access
You set up vercel ai sdk sql server read only access by creating a restricted database user. Then you pass those read-only credentials to your AI tool functions. Many teams start by reusing an admin account during early testing. If your app uses a broad role like db_owner, the model can change data or drop the database. How to set up vercel ai sdk sql server read only access First, choose how your AI app will log in to the database. SQL Server supports thirteen types of database users for dif
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You set up vercel ai sdk sql server read only access by creating a restricted database user. Then you pass those read-only credentials to your AI tool functions. Many teams start by reusing an admin account during early testing. If your app uses a broad role like db_owner, the model can change data or drop the database.
How to set up vercel ai sdk sql server read only access
First, choose how your AI app will log in to the database. SQL Server supports thirteen types of database users for different needs. A database user represents the identity of a login inside a database. If your app reads from many databases on one server, create a SQL login in master first. Then map that login to a user in each target database.
If your app only reads from one database, you have another option. You can create a contained database user with its own password. This user is not tied to a login in the master database. An admin must enable contained databases on the server and database first. All database roles, including the public role, have permission to connect.
Next, assign the user to the right fixed database role. Add the user as a member of the db_datareader fixed role. Members of db_datareader can read all data from all user tables and views. You can also add the user to the db_denydatawriter fixed role. Members of db_denydatawriter cannot add, change, or delete any table data. Note that you cannot change the permissions assigned to fixed database roles.
What native read-only roles solve and what they miss
Native database roles solve the problem of unwanted writes and schema changes. When your AI app logs in with db_datareader, it cannot delete rows. It also cannot alter tables or drop the database by mistake. This setup stops destructive queries even if a prompt tricks the model.
Still, native roles only check who logs in to the database. They do not inspect what individual queries do in flight. Because db_datareader grants read rights to all user tables, the AI can read everything. If a table holds emails, phone numbers, card numbers, or national IDs, the query returns them.
Auditor Read-Only Access + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
You can use the db_denydatareader role to block all reads across the database. Members of db_denydatareader cannot read data from any user tables or views. Yet fixed roles do not mask specific sensitive fields inside query results. Standard role permissions also do not link database queries back to a specific app user.
Why AI tool calls need query-level controls
When you build with the Vercel AI SDK, the model writes SQL on the fly. You define a tool function that accepts a query string from the model. Your app then runs that query against SQL Server using your database user. Every user of your AI app shares that single database login.
This shared login creates a gap for security and auditing teams. Database logs only show the shared app user, not the person who asked the question. Also, a single bad prompt can ask the model to dump an entire customer table. Without field masking, the database sends raw emails and card numbers back to the model.
Add runtime guardrails beside SQL Server
Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev runs beside the database as a sidecar for your SQL Server and checks TDS traffic without changing how clients log in.
With hoop.dev SQL Server controls, rules refuse banned statements before they run and can hold risky queries for human review. Matched sensitive values in supported result columns are masked before they reach the client. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.
Frequently asked questions
Can I edit the permissions of the db_datareader role in SQL Server?
No, SQL Server does not let you change the permissions of fixed database roles. If db_datareader is too broad, you must create a custom role and grant specific table permissions.
What is the difference between a standard SQL user and a contained user?
A standard SQL user maps to a server login stored in the master database. A contained database user authenticates directly inside the target database and does not need a master login.
Does db_datareader hide sensitive columns like emails or card numbers from AI queries?
No, members of db_datareader can read all data across all user tables and views. To hide specific fields in query results, you need data masking that rewrites matched fields.
Related guides
In this post