What i think what happened is that, before done, something already fired
res.send or res.end, so, when request.on('done') is executed, res is no
longer valid for send again.possibly,... connection.execSql(request); send something out. On Tue, Jan 8, 2013 at 11:37 PM, Bhoomi Kakaiya <[email protected]>wrote: > > Hi all, > > I am pretty new to Node. I am using Tediuos to get data from SQL database. > > Here is the code snippet : > > app.get('/getitems', function(req, res){ > res.contentType('application/json'); > var config = { userName: 'sa', password: 'pass', server: > '127.0.0.1', options : { database:'Auto'} > }; > var connection = new Connection(config); > connection.on('connect', function(err) { > executeStatement(res); > }); > function executeStatement(res1) { > console.log(res1.contentType); > request = new Request("select top 3 sItemId [Id], sName [Item], nrate1 > [Rate] from bmitem", function(err, rowCount) { > if (err) { > console.log(err); > } else { > console.log(rowCount + ' rows'); > } > connection.close(); > }); > > request.on('row', function(columns) { > columns.forEach(function(column) { > if (column.value === null) { > console.log('NULL'); > } else { > console.log(column.value); > } > }); > }); > request.on('done', function(rowCount, more) { > console.log(rowCount + ' rows returned'); > debugger; > res1.send("3");// Here is the problem. Debugger shows res1 is <error>. > }); > connection.execSql(request); > } > }); > > > The problem is response object has error. > I want to create json of the items returned from db and want to pass it as > json in the ajax request. > > If I return response in request.on("row") it works. Do not understand why > response object is not available on "done" event. > > Thanks in advance. > > Bhoomi. > > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
