Comments (4)
Hello, will you please add a complete example? Your example code doesn't do what your output shows. Also, please be sure to include your pool config.
from tedious-connection-pool.
Just FYI, the connection-pool will not give you the same connection again until you release it. I'm not sure why you think that it's the same connection, but that's not how the connection pool works.
One thing that I noticed when trying to run your example, is that you are setting i to 0 on every call to execute_SELECT_Statement. So i is always 0 when accessed.
from tedious-connection-pool.
Thanks a lot ben-page,
now my code works fine with your tip (i is always set to 0) as follows:
Changes:
" i " is called now " loop_count " and it is set to 0 at the end of any execute_SELECT_Statement()-call.
//Import tedious-connection-pool project.
var ConnectionPool = require('tedious-connection-pool');
var Request = require('tedious').Request;
/*
* Config varibale which includes important information about the Microsoft SQL database.
* Without port number specification, there wont be a connection!
*
*/
var connectionConfig = {
server: 'MSserver',
userName: 'user',
password: 'password',
options: {
database: 'databaseName',
port: 55555
}
};
var poolConfig = {
min: 1,
max: 10,
log: true
};
//Connection objects of the Microsoft SQL database.
//You need several connections, because 1 single connection is not able to work concurrent!
//Define a pool:
var pool = new ConnectionPool(poolConfig, connectionConfig);
/*
* db_uid_start: fixed first bytes for the MS-SQL datatype 'UniqueIdentifier'
* db_uid_end: last bytes of the UID
*
*/
var db_uid_start = '00000000-0000-0000-0000-';
var db_uid_end = '';
var sql_select_result_original = '';
var sql_select_result_fake = '';
var select_result = [];
var loop_count = 0;
//Make a Ms-SQL uniqueidentifier string format
//e.g. 00000000-0000-0000-0000-207754F45231
db_uid_end = db_uid_start.concat(peripheral.uuid);
//Execute SQL SELECT command
execute_SELECT_Statement('SELECT UID FROM table');
execute_SELECT_Statement('SELECT Name FROM table');
execute_SELECT_Statement('SELECT Address FROM table');
execute_SELECT_Statement('SELECT Brand FROM table');
execute_SELECT_Statement('SELECT Location FROM table');
display_Select_Result(select_result);
/*
* Function which selects from all database-tables
* Do not execute: "SELECT * FROM table"
* Always execute: "SELECT column FROM table"
*/
function execute_SELECT_Statement(sql_statement) {
pool.acquire(function(err, connection) {
if (err)
console.error(err);
//use the connection as normal
var request = new Request(sql_statement, function(err, rowCount) {
if (err)
console.error(err);
//console.log('rowCount: ' + rowCount);
//release the connection back to the pool when finished
connection.release();
});
connection.execSql(request);
request.on('row', function(columns) {
//console.log('value: ' + columns[0].value);
console.log('loop_count: ' + loop_count);
select_result[loop_count] = columns[0].value;
loop_count++;
});
//pool.drain();
});
loop_count = 0;
}
/*
* Function which displays content of any array
*/
function display_Select_Result(select_result) {
for (var l = 0; l < select_result.length; l++) {
console.log('select_result: ' + select_result[l] + '\n');
}
select_result = null;
select_result = [];
}
from tedious-connection-pool.
This code has a lot of problems.
- There is no guarantee the queries will return in the order you called them. They are just appended to the end of
select_result
, but that could be any order. For example, the query for Brand could easily return before the query for Address. - If there are multiple rows in
table
this would become even more problematic. The values from the columns in all the rows would just stuffed inselect_result
in a entirely unpredictable order. display_Select_Result
will never display anything.pool.acquire
is asynchronous. It's callback will always be executed after the call todisplay_Select_Result
is called in your code.- You don't need to do multiple queries to the same table. You can select multiple columns in a single query.
SELECT UID, Name FROM table
from tedious-connection-pool.
Related Issues (20)
- Issue with connection closed HOT 13
- Update memory-usage test to add validation. HOT 2
- Error: Acquire Timeout Exceeded for queued queries. HOT 6
- error thrown in tedious-connection-pool when calling release() HOT 2
- Acquire calls do not timeout if pool is drained.
- Support tedious 2.0.1? HOT 3
- Allow prepared statements to persist across returning a connection to the pool HOT 2
- new maintainer ? HOT 4
- Multiple Request On Multiple Connection HOT 1
- Error: connection.release is not a function HOT 1
- Incompatibility with Rollup HOT 1
- ConnectionError: Failed to connect to <server name> in 15000ms
- 1.0.5 release may be incompatible with tedious 5.x release HOT 1
- Pause()/resume() doesn't work as expected with connection from connectionPool
- Pool fills up with 'USED' connections - node app restart required as a result HOT 1
- Timeouts don't seem to work as expected
- Draining the pool after releasing connections may cause write to destroyed stream HOT 3
- TypeError: cb is not a function HOT 2
- Is this project dead? HOT 7
- request.transformIntoExecuteSqlRpc() is not a function HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tedious-connection-pool.