5
var edge = require('edge');

var getProduct = edge.func('sql', function () {/*
    select * from Products 
    where ProductId = @myProductId
*/});

getProduct({ myProductId: 10 }, function (error, result) {
    if (error) throw error;
    console.log(result);
});

This Code works well but I feel uncomfortable with setting the ConnectionString as ENVIROMENT_VARIALBE!

set EDGE_SQL_CONNECTION_STRING=Data Source=localhost;Initial Catalog=Northwind;Integrated Security=True

But I can´t find a different way to do this! Even on GitHub I can´t find another way on how to set ConnectionString! So I wonder is it even possible in OOB edge-sql.js to set the ConnectionString in Code?

2 Answers 2

7

After looking at the SourceCode of edge-sql, I was able to find out how it works, I wonder why on GitHub it is described with an EnviromentVariable?

Anyway here is the Code to set the ConnectionString in node.js :-)

var edge = require('edge');

var params = {
    connectionString: "Data Source=localhost;Initial Catalog=ITSM_604;Integrated Security=True",
    source: "select top 1 last_name from account_contact"
};

var getContacts = edge.func('sql', params);

getContacts(null, function(error, result){
    if (error) throw error;
    console.log(result);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, guys. You want to connect to SQL Server (in my case 2005) with integrated security? Use connectionString: "Data source=<sqlserver>;Integrated security=true" replace <sqlserver> with the host of your sql server in my case it's some pc on the network.
3

Evidently (https://github.com/tjanczuk/edge/issues/65), you can do it inline too:

var mySelect = edge.func('sql', {
    source: function () {/*
        select * from Product
    */},
    connectionString: 'your connection string goes here'
});

I don't like the environmental variable technique either.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.