Connect SQL Server to ChatGPT via DreamFactory: Step-by-Step Guide
by Kevin McGahey • November 13, 2025
In just a few steps, you can link your SQL Server database to ChatGPT using DreamFactory, eliminating the need for custom API development. DreamFactory automatically generates secure REST APIs for your database, enabling ChatGPT to interact with your data effortlessly. Here's a quick breakdown:
What You Need: SQL Server instance, DreamFactory account, API key, and OpenAI's ChatGPT API access.
How It Works: DreamFactory connects to SQL Server, auto-generates APIs, and secures them with role-based access control (RBAC) and API keys.
Integration Steps:
1. Configure DreamFactory to connect with your SQL Server.
2. Generate REST APIs for database tables and stored procedures.
3. Secure APIs using RBAC and IP whitelisting.
4. Use OpenAI's Agent Builder to connect ChatGPT with DreamFactory's APIs.
This approach ensures secure, real-time database interactions while maintaining U.S. standards for data formatting (dates, currency, etc.). Whether you're fetching customer details or generating sales reports, this guide simplifies the process.
Prerequisites and Setup Requirements
Before starting the integration process, you’ll need to ensure your system is ready and gather a few essential components. The good news? Most organizations already have many of these elements in place.
Required Components
To connect your SQL Server database with ChatGPT, you’ll need four main components working together.
First, you’ll need an operational SQL Server instance. DreamFactory supports SQL Server versions as old as 2005, so almost any modern deployment will suffice. Whether your server is hosted on-premises or in the cloud, as long as it’s accessible over the network, you’re good to go.
Next, you’ll need a DreamFactory instance and account. DreamFactory is an open-source platform, so you can start for free. You can install it locally via GitHub or deploy it using a cloud marketplace image. For enterprise-level features, such as additional database connectors or dedicated support, commercial licenses are available.
The third piece is your DreamFactory API key, which you can generate in the API Generation & Connections > API Keys section of the DreamFactory admin console after setting up your instance. This API key is critical for securing your endpoints and managing access to your SQL Server data.
Lastly, you’ll need access to OpenAI’s ChatGPT API, which requires an active OpenAI account with API credits.
Additionally, include the DreamFactory MCP Server Extension. This extension acts as a secure AI Data Gateway, allowing ChatGPT to interact with your database without exposing SQL credentials or granting direct access.
Once these components are in place, it’s time to ensure your system meets the necessary requirements.
System Requirements
DreamFactory is flexible and works across various environments and operating systems, but there are some specifics to keep in mind.
Operating Systems: DreamFactory supports Windows Server 2019/2022, several Linux distributions, Docker containers, and Kubernetes clusters.
For Windows Server deployments, you’ll need IIS Version 10 as your web server and non-thread-safe PHP 8.1.x (such as version 8.1.17). The PHP installation must include certain extensions for SQL Server connectivity: sqlsrv and pdo_sqlsrv for Windows, or pdo_dblib for Linux and Mac if sqlsrv isn’t supported. Additionally, PHP extensions like ldap, curl, openssl, and mbstring are required for full functionality.
Additional Software: You’ll also need Git for version control, the Visual C++ 2015-2019 redistributable, the URL rewrite IIS module, and Composer for managing PHP dependencies. These tools ensure DreamFactory can generate and manage your REST APIs effectively.
Database Permissions: Security is key here. Configure SQL Server to use either SQL Authentication or Windows Authentication for DreamFactory connections. Make sure your database supports the NVARCHAR data type, as it’s essential for handling international characters and special formatting.
Directory Permissions: On Windows Server, grant "Full Control" permissions to the IIS_USRS account for the storage and public directories, applying these permissions recursively. The user account tied to DreamFactory’s system database should also have full permissions on that database.
Network Configuration: Ensure HTTPS connections are enabled between DreamFactory, your SQL Server instance, and OpenAI’s API endpoints. Open port 443 for HTTPS traffic and port 1433 (default) for SQL Server.
Although DreamFactory simplifies API creation, having a basic understanding of REST API principles - like HTTP methods (GET, POST, PUT, DELETE) and JSON request/response formats - can make setup smoother and troubleshooting easier.
Setting Up DreamFactory for SQL Server
Once you've got the prerequisites sorted, it's time to configure DreamFactory to work seamlessly with your SQL Server database. This involves three core steps: connecting your database to DreamFactory, letting it auto-generate REST APIs, and setting up robust security measures.
Connecting SQL Server to DreamFactory
Start by logging into DreamFactory. Head over to API Generation & Connections > API Types > Database and create a new service for SQL Server.
From the available connectors, select SQL Server. Give your service a clear and descriptive name, like "CompanyDB" or "ProductionSQL" - this name will be part of your API endpoints.
Next, fill in the connection details:
Host: Enter your SQL Server's host address.
Port: Use the default port (1433) unless you’ve customized it.
Database Name: Specify the name of your SQL Server database.
Authentication: Input your SQL Server username and password for SQL Server Authentication. If you're using Windows Authentication, configure DreamFactory to run under a domain account.
In the Connection String field, add parameters like this:
Server=your-server;Database=your-database;Trusted_Connection=false;Encrypt=true;TrustServerCertificate=false
The encryption settings ensure your data stays secure during transit.
Once you've entered everything, test the connection. If successful, save your configuration. DreamFactory will analyze your database schema and prepare to generate APIs automatically. When the connection is confirmed, you’re ready to move on to the API generation step.
Generating REST APIs Automatically
Go to the API Docs tab and select your SQL Server service. DreamFactory will create ready-to-use CRUD endpoints for every table in your database. For example, if you have a "Customers" table, you’ll get endpoints like:
-GET /api/v2/your-service/_table/customers – Fetch all customer records.
-GET /api/v2/your-service/_table/customers/123 – Retrieve a specific customer by ID.
-POST /api/v2/your-service/_table/customers – Add a new customer record.
-PUT /api/v2/your-service/_table/customers/123 – Update an existing customer’s details.
-DELETE /api/v2/your-service/_table/customers/123 – Remove a customer record.
Stored procedures are also accessible under the _proc path, such as:
POST /api/v2/your-service/_proc/GetMonthlyReport
DreamFactory takes care of mapping SQL Server data types to JSON formats. For instance, DATETIME fields are converted to ISO 8601 strings, DECIMAL fields retain their precision, and NVARCHAR fields properly handle Unicode characters.
With your APIs ready, the next step is to secure them using role-based access control.
Setting Up Role-Based Access Control (RBAC)
To integrate ChatGPT, start by creating a role. Under Role Based Access, create one called "ChatGPT_Role." Assign access permissions for your SQL Server service based on what ChatGPT needs:
Grant GET access for reading data.
Add POST permissions if ChatGPT will create records.
You can fine-tune access further:
Use Advanced Filters to limit access to specific tables or rows.
Apply Field-Level Security to hide sensitive data, like Social Security numbers, ensuring ChatGPT only sees what's necessary.
For added control, set rate limits under “Security > Rate Limiting”. For example, allowing 100 requests per minute balances performance and prevents misuse.
Now, create an API key. Go to the API Generation & Connections > API Keys section, name the app "ChatGPT Integration", and assign the “ChatGPT_Role” as the Default Role. Click the “Active” toggle, select “Create”, and DreamFactory will generate a unique API key for authentication.
Before moving forward, test your configuration. Use the API key to make calls and ensure the permissions work as intended. Verify that unauthorized endpoints return proper error messages.
With your SQL Server connected, APIs generated, and security measures in place, you're all set to bridge your database with ChatGPT!
Securing and Customizing API Endpoints
Once you've set up DreamFactory, fine-tune your API endpoints for better performance and security. This involves implementing security best practices and leveraging built-in documentation tools.
CRUD Endpoint Considerations
DreamFactory generates endpoints automatically, but consider these optimizations for ChatGPT integration:
Read operations: Use query parameters to filter results effectively. For example, retrieve customers from specific states or products within a price range using URL parameters like ?filter=(state='CA'). Enable pagination to manage response sizes using limit and offset parameters to prevent overwhelming responses.
Update operations: Be selective about which fields ChatGPT can modify. For example, allow updates to customer contact details but lock down fields like account creation dates or internal reference numbers.
Delete operations: Consider using soft deletes (marking records as inactive) instead of permanent deletions. This preserves data integrity while treating records as "deleted" for active use.
Stored procedures: Ensure parameters are clearly defined. For instance, a procedure like "GetQuarterlySalesReport" should have well-documented parameters for start date, end date, and region code.
Applying Security Best Practices
Security is a critical factor when linking your database to AI systems. Here are some key measures to implement:
Encryption: Enforce SSL/TLS encryption to secure data during transmission. Configure this in your SQL Server connection settings.
API Key Management: Rotate API keys regularly (every 90 days recommended) to minimize security risk. See API Key Management for automation options.
Rate Limits: Set strict rate limits to prevent abuse or accidental overload.
Field-Level Security: Use DreamFactory's filtering tools to protect sensitive data like Social Security numbers or credit card details. Apply these settings consistently at the role level.
IP Whitelisting: Restrict access to only ChatGPT's known IP ranges.
Request Validation: DreamFactory automatically validates incoming data against your database schema, checking data types, field lengths, and required values.
Audit Logging: Enable logging to track API usage and detect unauthorized activity. For comprehensive security guidelines, see the Security FAQ.
Using Auto-Generated Swagger Documentation

DreamFactory simplifies integration by automatically creating Swagger documentation for your SQL Server endpoints. You can find this documentation in the API Docs tab of the DreamFactory admin panel.
Use the interactive Swagger docs to test your endpoints before integrating them with ChatGPT. For instance, you can verify that:
-Dates are formatted in ISO 8601. (YYYY-MM-DDTHH:MM:SS).
-Currency values have the correct precision.
-Text fields handle special characters properly.
The documentation also includes schema definitions that outline the structure of request and response data. These definitions are essential for configuring ChatGPT's API calls, ensuring that field types, required parameters, and example values align with your setup.
Authentication examples provided in the Swagger documentation are particularly helpful. Copy the API key usage examples directly when setting up ChatGPT connections, whether you're using header-based or query parameter authentication.
Additionally, the error response section details potential error codes and messages. Use this information to configure error handling in ChatGPT, ensuring it can respond gracefully to issues like validation errors or failed database operations.
Export the Swagger specification as a JSON or YAML file for easier integration. Many AI platforms support direct imports of these specifications, which can save you time during setup.
Finally, the Try It Out feature lets you test your endpoints with real data. This is a great way to confirm that your security settings and endpoint responses behave as expected under different scenarios.
With your endpoints customized, secured, and thoroughly documented, you're ready to connect DreamFactory with ChatGPT. This ensures a smooth, reliable, and secure exchange of data between your SQL Server database and your AI system.
Connecting DreamFactory APIs with ChatGPT
With your SQL Server APIs secured and documented, integrate them with ChatGPT to enable conversational data queries.
Setting Up ChatGPT with DreamFactory APIs
Use OpenAI's GPT Builder or Agent Builder to create a custom GPT that connects with your DreamFactory APIs. Access the builder through your OpenAI account.
In the configuration panel, import your DreamFactory API specification:
1. Go to the Actions section
2. Click Import from URL or Upload file
3. Upload the Swagger JSON file from DreamFactory's API Docs
This allows ChatGPT to understand your API endpoints, required parameters, and response formats.
Configure authentication by selecting API key authentication. Add your DreamFactory API key:
-Set authentication type to "API Key"
-Set the header name to "X-DreamFactory-API-Key"
-Enter your generated API key value
Define specific actions for database operations. For example:
-"Get customer orders" - maps to your customer orders endpoint
-"Search products" - queries your products table
-"Update inventory" - modifies stock levels
Use the preview feature to test your integration. Try queries like "Show me all orders from last month" to confirm ChatGPT formats API calls correctly and processes responses.
Formatting Requests and Handling Responses
Configure ChatGPT to handle data formats appropriately for your use case:
Date handling: Send dates to DreamFactory in ISO 8601 format (YYYY-MM-DDTHH:MM:SS) for consistency. When interpreting user queries, ChatGPT can recognize common date formats. For example, if a user asks for "sales data from March 15, 2024 to March 31, 2024", ChatGPT converts these to "2024-03-15T00:00:00" and "2024-03-31T23:59:59" for the API call.
Currency and numbers: Ensure currency values include proper formatting with dollar signs and decimals (e.g., $1,234.56) in user-facing responses. Use standard decimal notation in API calls.
Response parsing: Structure ChatGPT to extract and present meaningful information from JSON payloads. For example, a customer query should format fields like customer_id, first_name, last_name, email, and phone_number in a conversational format rather than raw JSON.
Error handling: Configure ChatGPT to recognize DreamFactory response codes:
401 - "I don't have permission to access that data"
404 - "I couldn't find records matching that criteria"
500 - "There was an error connecting to the database"
Response validation: Implement checks to ensure data meets expected formats - valid email addresses, properly formatted phone numbers, and numerical values within reasonable ranges.
Best Practices for AI Integration
Contextual responses: Configure ChatGPT to provide insights rather than just raw data. For example, when retrieving sales data, include context like "Sales increased by 15% compared to last month" instead of only listing figures.
Clarifying questions: Enable ChatGPT to ask for clarification on ambiguous requests. For instance, if multiple products match "wireless headphones", ChatGPT should ask, "I found three options: premium ($299), standard ($199), and budget ($99). Which one would you like to see?"
Multi-table queries: Configure actions that combine data from multiple tables. For example, a customer service query might pull from customers, orders, products, and support tickets to provide a complete view.
Response caching: For frequently accessed reference data (office hours, policies, product catalogs), consider caching to reduce database load and improve response times.
Testing and Troubleshooting the Integration
Test your DreamFactory API endpoints thoroughly before full deployment to ensure proper data retrieval and handling.
Test API Connectivity
Start with basic connectivity tests using tools like Postman, cURL, or your web browser. Test a simple read-only query:
GET https://your-dreamfactory-instance.com/api/v2/your-service/_table/customers
Include your API key in the request header:
X-DreamFactory-API-Key: your-api-key-here
This validates that the API is accessible and responding correctly.
Use the Swagger documentation in DreamFactory's API Docs tab to test different endpoints interactively. The "Try It Out" feature provides immediate feedback on request formatting and response data.
Read operations: Query tables with filters, pagination, and sorting
Error conditions: Try unauthorized requests, invalid IDs, and malformed data
Rate limiting: Verify rate limits trigger appropriate 429 responses
Field filtering: Confirm sensitive fields are properly hidden
Common Trouble Shooting
Connection failures:
Verify SQL Server is accessible from the DreamFactory host
Check firewall rules allow traffic on port 1433
Confirm SQL Server authentication credentials are correct
Ensure SQL Server is configured to accept TCP/IP connections
Authentication errors:
Verify API key is active in DreamFactory admin console
Check API key is correctly formatted in request headers
Confirm the assigned role has appropriate permissions
Data format issues:
Review data type mappings in API responses
Check character encoding for special characters
Verify date/time formats match expected ISO 8601 standard
Performance problems:
Enable database query logging to identify slow queries
Review indexes on frequently queried columns
Adjust pagination limits for large result sets
Consider implementing caching for reference data
For additional troubleshooting guidance and common solutions, consult the DreamFactory Security FAQ and database API documentation.
Verifying U.S. Localization in API Responses
When testing, double-check that API responses align with U.S. localization standards. This includes proper formatting for dates, currency, and measurements, ensuring the data meets the needs of users in the United States. Adjust settings in DreamFactory or your SQL Server configuration if necessary.
Conclusion
Integrating SQL Server with ChatGPT using DreamFactory provides automated REST endpoint generation with robust security features, eliminating the need for custom API development. This guide has demonstrated how to:
-Connect SQL Server to DreamFactory and generate APIs automatically
-Implement role-based access control and API key authentication
-Configure ChatGPT to interact with your database through DreamFactory's APIs
-Test and troubleshoot the integration
By leveraging DreamFactory's automated API generation, built-in security features, and comprehensive documentation, you can create a production-ready integration between your SQL Server database and ChatGPT. The platform's support for multiple authentication methods, granular access controls, and audit logging ensures your data remains secure throughout the integration.
FAQs
How does DreamFactory keep my SQL Server data secure when connecting it to ChatGPT?
DreamFactory implements multiple layers of security to protect your SQL Server data. The platform uses parameterized queries and input validation to prevent SQL injection attacks. DreamFactory never exposes database credentials to external systems - instead, it acts as a secure API gateway that handles authentication through API keys.
Additionally, DreamFactory provides role-based access control (RBAC), API key management with rotation capabilities, field-level security to hide sensitive data, and comprehensive audit logging to track all API access. All connections use SSL/TLS encryption to protect data in transit.
What are the main advantages of using DreamFactory to connect SQL Server with ChatGPT instead of building custom APIs?
Using DreamFactory to connect SQL Server with ChatGPT provides several advantages over custom API development:
Time savings: DreamFactory automatically generates REST APIs for your database tables and stored procedures, eliminating weeks or months of custom development
Built-in security: Get SQL injection protection, RBAC, API key authentication, and audit logging without custom implementation
Automatic documentation: Swagger/OpenAPI documentation is generated automatically for all endpoints
Maintenance reduction: Database schema changes automatically reflect in APIs without code updates
Standardization: All APIs follow consistent REST conventions and response formats
Scalability: Enterprise-grade performance without custom optimization
The platform handles database connection pooling, request validation, and error handling automatically, allowing you to focus on business logic rather than infrastructure.
What should I do if I face connectivity problems between DreamFactory and my SQL Server during integration?
If you experience connectivity issues:
Verify connection details: Double-check server address, port (default 1433), database name, username, and password in the DreamFactory service configuration.
Check SQL Server configuration:
Ensure SQL Server is configured to accept TCP/IP connections
Verify SQL Server Authentication mode allows your chosen authentication type
Confirm the database user has appropriate permissions
Review network settings:
Check firewall rules allow traffic between DreamFactory and SQL Server on port 1433
Verify any cloud security groups or network ACLs permit the connection
Test network connectivity using telnet or similar tools
Review DreamFactory logs: Check the DreamFactory application logs for specific error messages that can pinpoint the issue.
Test with SQL tools: Use SQL Server Management Studio or another client from the DreamFactory host to confirm basic connectivity.
For comprehensive guidance, refer to the DreamFactory SQL Server documentation. For persistent issues, contact DreamFactory support with your configuration details and error logs.
Kevin McGahey is an accomplished solutions engineer and product lead with expertise in API generation, microservices, and legacy system modernization, as demonstrated by his successful track record of facilitating the modernization of legacy databases for numerous public sector organizations.
