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.
# SQL Server with SQL AuthenticationServer=localhost;Database=myapp;User Id=sa;Password=YourPassword123;TrustServerCertificate=True# With instance nameServer=localhost\SQLEXPRESS;Database=myapp;User Id=sa;Password=pass;TrustServerCertificate=True# Using IP addressServer=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).
# Remote server with SQL AuthenticationServer=db.example.com;Database=production;User Id=admin;Password=secure123;TrustServerCertificate=True# Remote server with custom portServer=db.example.com,1433;Database=production;User Id=admin;Password=secure123;TrustServerCertificate=True# Remote server with encryptionServer=db.example.com;Database=production;User Id=admin;Password=secure123;Encrypt=True;TrustServerCertificate=False
Ensure SQL Server is configured for remote connections and TCP/IP is enabled in SQL Server Configuration Manager.
# Connection timeoutServer=localhost;Database=myapp;User Id=sa;Password=pass;Connection Timeout=30;TrustServerCertificate=True# Command timeoutServer=localhost;Database=myapp;User Id=sa;Password=pass;Command Timeout=60;TrustServerCertificate=True# Connection poolingServer=localhost;Database=myapp;User Id=sa;Password=pass;Pooling=true;Max Pool Size=100;TrustServerCertificate=True# Multiple Active Result Sets (MARS)Server=localhost;Database=myapp;User Id=sa;Password=pass;MultipleActiveResultSets=true;TrustServerCertificate=True# Application name (visible in SQL Server logs)Server=localhost;Database=myapp;User Id=sa;Password=pass;Application Name=Queryly;TrustServerCertificate=True
Using TrustServerCertificate=True disables certificate validation and makes connections vulnerable to man-in-the-middle attacks. Only use in trusted environments.
queryly data query ProductionSQL# Query tables with schema prefixSQL> SELECT * FROM dbo.Users;SQL> SELECT * FROM sales.Customers;SQL> SELECT * FROM hr.Employees;# Cross-schema joinsSQL> SELECT u.name, o.total FROM dbo.Users u JOIN sales.Orders o ON u.id = o.user_id;
queryly data query ProductionSQL# Select queriesSQL> SELECT * FROM dbo.Users;SQL> SELECT TOP 10 * FROM dbo.Orders;SQL> SELECT name, email FROM dbo.Customers WHERE created_at > '2024-01-01';
# TOP instead of LIMITSQL> SELECT TOP 100 * FROM dbo.Orders;# Window functionsSQL> SELECT name, salary, ROW_NUMBER() OVER (ORDER BY salary DESC) as rank FROM dbo.Employees;# Common Table Expressions (CTE)SQL> WITH TopCustomers AS ( SELECT customer_id, SUM(total) as total_sales FROM dbo.Orders GROUP BY customer_id ) SELECT c.name, tc.total_sales FROM TopCustomers tc JOIN dbo.Customers c ON tc.customer_id = c.id ORDER BY tc.total_sales DESC;# Date functionsSQL> SELECT DATEPART(year, created_at) as year, DATEPART(month, created_at) as month, COUNT(*) as count FROM dbo.Orders GROUP BY DATEPART(year, created_at), DATEPART(month, created_at);
# Database sizeSQL> EXEC sp_spaceused;# Table sizesSQL> SELECT t.name as TableName, s.name as SchemaName, p.rows as RowCount, SUM(a.total_pages) * 8 as TotalSpaceKB FROM sys.tables t INNER JOIN sys.schemas s ON t.schema_id = s.schema_id INNER JOIN sys.indexes i ON t.object_id = i.object_id INNER JOIN sys.partitions p ON i.object_id = p.object_id AND i.index_id = p.index_id INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id WHERE t.is_ms_shipped = 0 GROUP BY t.name, s.name, p.rows ORDER BY SUM(a.total_pages) DESC;# Current database and userSQL> SELECT DB_NAME() as CurrentDatabase, SUSER_NAME() as CurrentUser;# SQL Server versionSQL> SELECT @@VERSION;
# Add connectionqueryly connect add# name: MySQLServer# type: SQL Server# connection string: Server=localhost;Database=myapp;User Id=sa;Password=pass;TrustServerCertificate=True# Test connectionqueryly connect test MySQLServer# List all tables (with schemas)queryly schema list MySQLServer
# View schema as treequeryly schema tree MySQLServer# Check table structure (use schema.table)queryly schema info MySQLServer dbo.Users# Browse table dataqueryly data browse MySQLServer dbo.Users# Export to CSVqueryly data export MySQLServer dbo.Users csv
# Enter query modequeryly data query MySQLServer# Analyze dataSQL> SELECT TOP 30 CAST(created_at AS DATE) as date, COUNT(*) as order_count, SUM(total) as total_sales FROM dbo.Orders GROUP BY CAST(created_at AS DATE) ORDER BY date DESC;SQL> SELECT status, COUNT(*) as count, AVG(total) as avg_total FROM dbo.Orders GROUP BY status;SQL> exit
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 instanceGet-Service MSSQL$SQLEXPRESS
Login failed
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';
Certificate validation failed
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 developmentServer=localhost;Database=myapp;User Id=sa;Password=pass;TrustServerCertificate=True
Database does not exist
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 databasesSELECT name FROM sys.databases;-- Create databaseCREATE DATABASE myapp;-- Grant accessUSE myapp;CREATE USER appuser FOR LOGIN appuser;ALTER ROLE db_datareader ADD MEMBER appuser;ALTER ROLE db_datawriter ADD MEMBER appuser;
Named instance not found
Error: SQL Server does not exist or access deniedSolutions:
# Start SQL Server Browser service (Windows)Start-Service SQLBrowser# Or use explicit portServer=localhost,1433;Database=myapp;User Id=sa;Password=pass;TrustServerCertificate=True