Skip to main content
SQL Server is Microsoft’s enterprise-grade relational database management system. Queryly provides full support for SQL Server, including LocalDB, named instances, and remote servers.

Connection String Format

The standard SQL Server connection string format:
Server=localhost;Database=mydb;User Id=sa;Password=secret;TrustServerCertificate=True

Connection Examples

Standard Local SQL Server

# SQL Server with SQL Authentication
Server=localhost;Database=myapp;User Id=sa;Password=YourPassword123;TrustServerCertificate=True

# With instance name
Server=localhost\SQLEXPRESS;Database=myapp;User Id=sa;Password=pass;TrustServerCertificate=True

# Using IP address
Server=127.0.0.1;Database=myapp;User Id=sa;Password=pass;TrustServerCertificate=True
TrustServerCertificate=True is required when connecting to SQL Server without a valid SSL certificate (common in development).

Adding a SQL Server Connection

Interactive Mode

queryly connect add
Example session:
$ queryly connect add
Enter connection name: ProductionSQL
Select database type: SQL Server
Enter connection string: Server=localhost;Database=myapp;User Id=sa;Password=YourPassword123;TrustServerCertificate=True
 Connection test successful!
 Connection 'ProductionSQL' saved

Supported Features

Connection Management - Add, test, list, and remove connections
Schema Exploration - List tables with schema support (dbo, custom schemas)
Table Browsing - View table data with proper type handling
Query Execution - Run T-SQL queries with SQL Server extensions
Data Export - Export tables to CSV or JSON formats
SQL Server supports multiple schemas (e.g., dbo, sales, hr). Queryly displays tables with their schema names.

TrustServerCertificate Explained

What is TrustServerCertificate?

The TrustServerCertificate parameter controls SSL/TLS certificate validation:
Server=localhost;Database=myapp;User Id=sa;Password=pass;TrustServerCertificate=True
Use when:
  • Connecting to localhost/LocalDB
  • Development environments
  • Self-signed certificates
  • Testing scenarios
Using TrustServerCertificate=True disables certificate validation and makes connections vulnerable to man-in-the-middle attacks. Only use in trusted environments.

Common Scenarios

ScenarioSettingExplanation
LocalDBTrustServerCertificate=TrueLocalDB uses self-signed certificates
Local SQL ExpressTrustServerCertificate=TrueDefault installation has no valid certificate
Azure SQL DatabaseTrustServerCertificate=FalseAzure provides valid certificates
Production (valid cert)TrustServerCertificate=FalseValidate certificate for security
Production (self-signed)TrustServerCertificate=TrueOnly if you trust the server

Schema Support

SQL Server organizes tables into schemas. Queryly fully supports this:

Understanding Schemas

# Tables are displayed with schema prefix
queryly schema list ProductionSQL
# Output:
# dbo.Users
# dbo.Orders
# sales.Customers
# hr.Employees

Querying with Schemas

queryly data query ProductionSQL

# Query tables with schema prefix
SQL> SELECT * FROM dbo.Users;
SQL> SELECT * FROM sales.Customers;
SQL> SELECT * FROM hr.Employees;

# Cross-schema joins
SQL> SELECT u.name, o.total 
     FROM dbo.Users u 
     JOIN sales.Orders o ON u.id = o.user_id;

Browsing Schema Tables

# Browse table (specify full schema.table name)
queryly data browse ProductionSQL dbo.Users
queryly data browse ProductionSQL sales.Customers

# View table structure
queryly schema info ProductionSQL dbo.Users

SQL Server-Specific Features

Data Type Support

Queryly handles SQL Server’s rich type system:
  • Numeric: int, bigint, decimal, numeric, float, real, money
  • Text: varchar, nvarchar, char, nchar, text, ntext
  • Date/Time: datetime, datetime2, date, time, datetimeoffset
  • Binary: binary, varbinary, image
  • Other: bit, uniqueidentifier, xml, sql_variant
  • Spatial: geography, geometry

T-SQL Query Examples

queryly data query ProductionSQL

# Select queries
SQL> SELECT * FROM dbo.Users;
SQL> SELECT TOP 10 * FROM dbo.Orders;
SQL> SELECT name, email FROM dbo.Customers WHERE created_at > '2024-01-01';

Common Workflows

# Add connection
queryly connect add
# name: MySQLServer
# type: SQL Server
# connection string: Server=localhost;Database=myapp;User Id=sa;Password=pass;TrustServerCertificate=True

# Test connection
queryly connect test MySQLServer

# List all tables (with schemas)
queryly schema list MySQLServer

Troubleshooting

Error: A network-related or instance-specific error occurredSolutions:
  • Verify SQL Server is running (SQL Server Service)
  • Enable TCP/IP in SQL Server Configuration Manager
  • Check firewall rules (port 1433)
  • Verify server name and instance name
# Check SQL Server service status (Windows)
Get-Service MSSQLSERVER

# Or for named instance
Get-Service MSSQL$SQLEXPRESS
Error: Login failed for user 'sa'Solutions:
  • Verify username and password
  • Enable SQL Server Authentication (Mixed Mode)
  • Check user account is not locked or disabled
  • For Windows Auth, ensure proper domain/workgroup setup
-- Enable SQL Server Authentication
-- In SSMS, right-click server → Properties → Security → SQL Server and Windows Authentication mode

-- Reset SA password (Windows Auth required)
ALTER LOGIN sa ENABLE;
ALTER LOGIN sa WITH PASSWORD = 'NewPassword123';
Error: The certificate chain was issued by an authority that is not trustedSolutions:
  • Add TrustServerCertificate=True to connection string
  • Install a valid SSL certificate on SQL Server
  • For Azure SQL, ensure TrustServerCertificate=False
# For local development
Server=localhost;Database=myapp;User Id=sa;Password=pass;TrustServerCertificate=True
Error: Cannot open database "myapp" requested by the loginSolutions:
  • Verify database name (case-insensitive but must match)
  • Create the database if needed
  • Check user has access to the database
-- List databases
SELECT name FROM sys.databases;

-- Create database
CREATE DATABASE myapp;

-- Grant access
USE myapp;
CREATE USER appuser FOR LOGIN appuser;
ALTER ROLE db_datareader ADD MEMBER appuser;
ALTER ROLE db_datawriter ADD MEMBER appuser;
Error: SQL Server does not exist or access deniedSolutions:
  • Verify instance name: Server=localhost\INSTANCENAME
  • Enable SQL Server Browser service
  • Use server name with port: Server=localhost,1433
# Start SQL Server Browser service (Windows)
Start-Service SQLBrowser

# Or use explicit port
Server=localhost,1433;Database=myapp;User Id=sa;Password=pass;TrustServerCertificate=True

Best Practices

Use Windows Authentication when possible for better security
Enable encryption for remote connections
Use schemas to organize tables logically (sales, hr, etc.)
Regular backups - use SQL Server backup tools or scripts
Monitor connections - use SQL Server Management Studio or DMVs
Avoid:
  • Using sa account for applications (create dedicated users)
  • TrustServerCertificate=True in production with remote servers
  • Default passwords on SQL Server instances
  • Exposing SQL Server directly to the internet

Working with Commands

SQL Server works with all Queryly commands:
# Connection management
queryly connect add
queryly connect list
queryly connect test MySQLServer
queryly connect remove MySQLServer

# Schema exploration (note: schema.table format)
queryly schema list MySQLServer
queryly schema info MySQLServer dbo.Users
queryly schema tree MySQLServer

# Data operations (use schema.table format)
queryly data browse MySQLServer dbo.Users
queryly data query MySQLServer
queryly data export MySQLServer dbo.Users csv
queryly data export MySQLServer dbo.Orders json

Command Reference

See the complete command reference for all available options

Next Steps

Schema Exploration

Learn how to explore SQL Server schemas

Data Operations

Browse and query table data

Providers Overview

Compare all database providers

Connection Management

Manage your database connections

Build docs developers (and LLMs) love