2017-09-14 9 views
0

, 다음과 같이 이루어집니다 : 연결이 완료지루한 구성 (Node.js)을 정의 할 때 데이터베이스를 지정하는 방법이 있습니까? 데이터베이스에 연결 <a href="http://tediousjs.github.io/tedious/getting-started.html" rel="nofollow noreferrer">Tedious Getting Started Guide</a>에 따르면

var Connection = require('tedious').Connection; 

     var config = { 
     userName: 'test', 
     password: 'test', 
     server: '192.168.1.210', 

     // If you're on Windows Azure, you will need this: 
     options: {encrypt: true} 
     }; 

     var connection = new Connection(config); 

     connection.on('connect', function(err) { 
     // If no error, then good to go... 
      executeStatement(); 
     } 
    ); 

되면, 쿼리는 다음과 같이 수행 할 수 있습니다

var Request = require('tedious').Request; 

    function executeStatement() { 
    request = new Request("select 42, 'hello world'", function(err, rowCount) { 
     if (err) { 
     console.log(err); 
     } else { 
     console.log(rowCount + ' rows'); 
     } 
    }); 

    request.on('row', function(columns) { 
     columns.forEach(function(column) { 
     console.log(column.value); 
     }); 
    }); 

    connection.execSql(request); 
    } 

이 매력처럼 작동 그러나 다음과 같이 요청을 변경하고 싶습니다.

request = new Request("select * from table", function(err, rowCount) { 

분명히이 요청은 다음과 같이 변경 될 수 있습니다. 따라서 config 객체에 정의 된 데이터베이스는 SQL에서 테이블을 인식하지 못합니다.

database: 'mydb' 

난 여전히 다음과 같은 오류가 점점 오전 :는 config 객체의 데이터베이스를 정의하는 올바른 방법을 무엇

Invalid object name 'table'.

나는 추가하여 구성 객체에 다음과 같은 시도 ?

답변

1

는 config 객체는 다음과 같이해야합니다 :

var config = { 
    userName: 'username', 
    password: 'password', 
    server: 'server', 
    options: { 
     database: "databaseName", 
    } 
};