node-mssql

Node : how to convert from varbinary to image of SQL Server datatype

爷,独闯天下 提交于 2021-02-08 09:58:17
问题 I'm have a SQL Server database with images of type varbinary . I need to convert the varbinary and return the image to a web page. Help would be appreciated. I found this and it was very helpful, but I need it in reverse. Node.js How to convert to image from varbinary of MS Sql server datatype Something like ... var image = new Buffer(rs.recordset[0].Image).toString('base64'); res.type('image/jpeg; charset=utf-8'); res.status(200).end(image); <ng-template ngbSlide *ngFor="let image of images"

How to insert binary data into sql server using node-mssql

雨燕双飞 提交于 2021-01-28 04:08:37
问题 I'm downloading an image using node/request module, and I'm trying to figure out how to insert that image into a varbinary field in sql server using the node/mssql module. So far I have tried putting a cast into the insert statement, converting the body (buffer) to a string, all to no avail. I'm trying to figure out how to do this without using a stored procedure. Thanks! 回答1: I've read in a .png image file from disk as 'binary', and then put that into a 'binary' buffer, and then was able to

Transaction for prepared statements using Node mssql

早过忘川 提交于 2021-01-27 12:05:13
问题 I want to create an Express REST API and will use MSSQL for the database part. I use the mssql module and use the PreparedStatement class. Sometimes my queries have to be transactional, so I have to work with the Transaction class too. I found some information about prepared statements here and about transactions here but don't know how to execute transactional queries using prepared statements. Would someone mind explaining how to use the mssql module with prepared statements within

nodejs mssql - Too many parameters passed Stored procedure

两盒软妹~` 提交于 2020-01-16 04:51:45
问题 I running into "Too many parameters passed" to stored procedure while trying to run a stored procedure in NodeJs using mssql . Code: //This computerName is what we'll find in our mssql server to see //if the server entry exist or not and the stored procedure will take this as a parameter. var computerName = "some.fake.server.com"; var secProfile = ""; //Logic // If computerName passed is valid and not null. //if (computerName != "") { var sql = require('mssql'); var config = { user: 'dbuser',

node-mssql insert returning undefined recordset

这一生的挚爱 提交于 2020-01-05 09:07:06
问题 Select statements are working fine, but whenever I try an insert or update the recordset and affected values are undefined. The insert/update works in the DB, I just can't read the returned values. var sql = require('mssql'); var config = {...}; sql.connect(config).then(function() { new sql.Request().query("INSERT INTO MyTable (Name, Age) VALUES ('John', 30)").then(function(recordset, affected) { console.log('Recordset: ' + recordset); console.log('Affected: ' + affected); }).catch(function

node-mssql insert returning undefined recordset

青春壹個敷衍的年華 提交于 2020-01-05 09:07:00
问题 Select statements are working fine, but whenever I try an insert or update the recordset and affected values are undefined. The insert/update works in the DB, I just can't read the returned values. var sql = require('mssql'); var config = {...}; sql.connect(config).then(function() { new sql.Request().query("INSERT INTO MyTable (Name, Age) VALUES ('John', 30)").then(function(recordset, affected) { console.log('Recordset: ' + recordset); console.log('Affected: ' + affected); }).catch(function

Error while running node-mssql query

依然范特西╮ 提交于 2019-12-24 01:18:13
问题 I am trying to run node-mssql query, if I run simple quires it is getting executed. But when I use OPENROWSET and Microsoft.ACE.OLEDB.12.0 , it is showing some errors. Here is server.js code var express = require('express'); var app = express(); app.get('/', function (req, res) { var sql = require("mssql"); // config for your database var config = { user: '..', password: '....', server: 'localhost\\SQLEXPRESS', database: 'test_databasae' }; // connect to your database sql.connect(config,

How do I use Sinon to stub interaction with a database using mssql library?

走远了吗. 提交于 2019-12-23 02:41:38
问题 Using the node-mssql library to pull data from SQL. I've been using Sinon for a while now (written about 200 tests with it); having a ton of trouble getting my head around how to stub this library out. The code looks like: var sql = require('mssql'); var conn = new sql.Connection(sqlConfig); // sqlConfig is connection info, defined elsewhere conn.connect(function(err) { var req, selectFromTable; if (err != null) { // handle error } req = new sql.Request(conn); selectFromTable = "select * from

Node.js npm mssql function returning undefined

可紊 提交于 2019-12-12 20:09:06
问题 I am using mssql with node.js to connect to an sql server db. I am trying to reduce code by wrapping the connection code in a function with one query parameter. When I call the function from with in a router.get function, it returns undefined. Any help would be much appreciated. function sqlCall(query) { var connection = new sql.Connection(config, function(err) { if (err) { console.log("error1"); return; } var request = new sql.Request(connection); // or: var request = connection.request();

Need to keep promise result in a variable for Nodejs mssql validation

你。 提交于 2019-12-12 03:34:40
问题 let RetrieveFromDb=(queryStr) => { let sql=require('mssql'); let config={ server:'127.0.0.1', database:'TestDB', user:'user', password:'user', }; let dbConn=new sql.Connection(config); return dbConn.connect().then(function (){ let request=new sql.Request(dbConn); return request.query(queryStr) .then(function(recordset) { return recordset; dbConn.close(); }).catch(function (err) { console.log(err); dbConn.close(); }); }).catch(function (err) { console.log(err); }); }; RetrieveFromDb("Select