xShaider / testingan

1 stars 0 forks source link

JavaScript #1

Open xShaider opened 11 months ago

xShaider commented 11 months ago

const sql = require('mssql');

// Configuration for your SQL Server database with Windows Authentication const config = { server: 'your-server-name', // Replace with your SQL Server instance name database: 'your-database-name', options: { trustedConnection: true, // Use Windows Authentication // Uncomment the line below if you need to specify a domain // domain: 'your-domain-name' // Replace with your Windows domain } };

// Create a pool of connections const pool = new sql.ConnectionPool(config);

// Connect to the database using the pool pool.connect().then(() => { console.log('Connected to the SQL Server database');

// Now, you can perform database operations here // For example, you can execute SQL queries using pool.request()

}).catch((err) => { console.error('Error connecting to the database:', err); });

// Close the database connection when you're done pool.on('close', () => { console.log('Disconnected from the database'); process.exit(); // This ensures that the Node.js process exits when the database connection is closed });