modified db con for better connection handling mssql
This commit is contained in:
parent
378b9adf4d
commit
03fc743eb4
@ -29,6 +29,8 @@ export class OracleDBService {
|
||||
@Injectable()
|
||||
export class MssqlDBService {
|
||||
private pool: ConnectionPool;
|
||||
private poolConnected: boolean = false;
|
||||
|
||||
private readonly config = {
|
||||
...MssqlConfig,
|
||||
pool: {
|
||||
@ -39,22 +41,25 @@ export class MssqlDBService {
|
||||
};
|
||||
|
||||
constructor() {
|
||||
this.initializePool();
|
||||
}
|
||||
|
||||
private initializePool() {
|
||||
this.pool = new ConnectionPool(this.config);
|
||||
}
|
||||
|
||||
async getConnection(): Promise<Connection> {
|
||||
async getConnection(): Promise<ConnectionPool> {
|
||||
try {
|
||||
const connection = await this.pool.connect();
|
||||
console.log('Database connection initialized successfully for Mssql.');
|
||||
// console.log(`Connection established to server: ${this.config.server}`); // Log server info
|
||||
return connection;
|
||||
if (!this.poolConnected) {
|
||||
this.pool.on('error', err => {
|
||||
console.error('SQL Pool Error:', err);
|
||||
this.poolConnected = false;
|
||||
});
|
||||
|
||||
await this.pool.connect();
|
||||
this.poolConnected = true;
|
||||
console.log('Database connection pool initialized.');
|
||||
}
|
||||
return this.pool;
|
||||
} catch (error) {
|
||||
console.error('Error getting connection from pool', error.stack);
|
||||
throw error; // Rethrow the error after logging
|
||||
console.error('Failed to get connection from pool:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,10 +114,6 @@ export class ManageClientsService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -132,10 +128,6 @@ export class ManageClientsService {
|
||||
return { data: result.recordset };
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -193,10 +185,6 @@ export class ManageClientsService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -270,10 +258,6 @@ export class ManageClientsService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -329,10 +313,6 @@ export class ManageClientsService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@ -387,10 +367,6 @@ export class ManageClientsService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@ -463,10 +439,6 @@ export class ManageClientsService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@ -518,10 +490,6 @@ export class ManageClientsService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@ -571,10 +539,6 @@ export class ManageClientsService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@ -623,10 +587,6 @@ export class ManageClientsService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -97,10 +97,6 @@ export class ManageHoldersService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@ -118,10 +114,6 @@ export class ManageHoldersService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -154,10 +146,6 @@ export class ManageHoldersService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -186,10 +174,6 @@ export class ManageHoldersService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -207,10 +191,6 @@ export class ManageHoldersService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -230,10 +210,6 @@ export class ManageHoldersService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -251,10 +227,6 @@ export class ManageHoldersService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -272,10 +244,6 @@ export class ManageHoldersService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -293,10 +261,6 @@ export class ManageHoldersService {
|
||||
} catch (error) {
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -19,10 +19,6 @@ export class MssqlService {
|
||||
} catch (error) {
|
||||
console.error('Error checking connection:', error);
|
||||
return {error:error.message}
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -34,10 +34,6 @@ export class ParamTableService {
|
||||
return { data: result.recordset };
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -53,10 +49,6 @@ export class ParamTableService {
|
||||
return { data: result.recordset };
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,10 +72,6 @@ export class ParamTableService {
|
||||
return { data: result.recordset };
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,10 +94,6 @@ export class ParamTableService {
|
||||
return { data: result.recordset };
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,10 +109,6 @@ export class ParamTableService {
|
||||
return { data: result.recordset };
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,10 +123,6 @@ export class ParamTableService {
|
||||
return { data: result.recordset };
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,10 +21,6 @@ export class CarnetSequenceService {
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,10 +40,6 @@ export class CarnetSequenceService {
|
||||
} catch (error) {
|
||||
console.error('Error executing stored procedure:', error);
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,11 +18,9 @@ export class RegionService {
|
||||
return { data: result.recordset };
|
||||
|
||||
} catch (error) {
|
||||
console.log("Error is here ...");
|
||||
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,10 +37,6 @@ export class RegionService {
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,10 +52,6 @@ export class RegionService {
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,10 +21,6 @@ export class SpContactsService {
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,10 +36,6 @@ export class SpContactsService {
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,10 +51,6 @@ export class SpContactsService {
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,10 +75,6 @@ export class SpContactsService {
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,10 +89,6 @@ export class SpContactsService {
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,10 +112,6 @@ export class SpContactsService {
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,10 +20,6 @@ export class SpService {
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,10 +35,6 @@ export class SpService {
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,10 +64,6 @@ export class SpService {
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,10 +94,6 @@ export class SpService {
|
||||
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user