Overview
The Canchas Deportivas application uses SQL Server with integrated Windows authentication. All database connections are managed through theCD_conexion class in the data access layer.
Connection String
The application uses the following connection string configuration:Connection String Parameters
| Parameter | Value | Description |
|---|---|---|
| Data Source | JONATHANCASTILL\SQLEXPRESS | SQL Server instance name |
| Initial Catalog | DB_canchasdeportivas | Database name |
| Integrated Security | True | Use Windows Authentication |
| Encrypt | True | Encrypt the connection |
| Trust Server Certificate | True | Trust the server certificate |
CD_conexion Class
TheCD_conexion class manages database connectivity for all data access operations.
Location: capa_dato/CD_conexion.cs
Setup Instructions
1. Install SQL Server
Download and install SQL Server Express:2. Create the Database
Connect to your SQL Server instance and create the database:3. Create Tables
Execute the following SQL scripts to create the required tables:4. Create Stored Procedures
Refer to the Stored Procedures documentation for the complete list of stored procedures to create.5. Update Connection String
Modify the connection string inCD_conexion.cs to match your environment:
YOUR_SERVER_NAME with your actual SQL Server instance name.
NuGet Packages
The application requires the following NuGet package for SQL Server connectivity:Connection Management
Opening a Connection
All data access classes inherit fromCD_conexion and use the abrir_conexion() method:
Closing a Connection
Connections are automatically closed when using theusing statement, but can also be explicitly closed:
Environment-Specific Configuration
Development Environment
For local development, use the default connection string with your local SQL Server Express instance.Production Environment
For production, consider:- Use Configuration Files: Store connection strings in
appsettings.jsonorweb.config - Use SQL Authentication: Instead of Integrated Security, use SQL Server authentication
- Use Connection Pooling: Enable connection pooling for better performance
- Encrypt Sensitive Data: Store connection strings securely using encryption or Azure Key Vault
Example appsettings.json
Reading from Configuration
Troubleshooting
Connection Failed
If you receive a connection error:-
Verify SQL Server is running:
- Check if TCP/IP is enabled in SQL Server Configuration Manager
-
Verify the server name:
Authentication Failed
For Windows Authentication issues:- Ensure your Windows user has access to SQL Server
- Check SQL Server Authentication mode (should allow Windows Authentication)
- Grant appropriate permissions to your Windows user account
Database Not Found
If the database doesn’t exist:Security Best Practices
- Never hardcode credentials - Use configuration files or environment variables
- Use least privilege - Grant only necessary permissions to database users
- Enable encryption - Always use
Encrypt=Truein production - Use parameterized queries - Prevent SQL injection (handled by stored procedures)
- Regular backups - Implement automated database backup strategies
- Monitor connections - Track open connections and potential leaks