简体   繁体   中英

Connecting to database using msnodesqlv8 nodejs

I have the below nodejs code to connect to database:

const  sql  =  require("msnodesqlv8");
const connectionString = "Server={remote}; Database={Products}; Trusted_Connection=Yes;Driver={SQL Server Native Client 11.0}; "
const query = "SELECT * FROM Products"
sql.query(connectionString,  query,   (err,  rows)  =>  {    
    console.log(rows);
});

This code works fine if I have Microsoft SQL studio installed, and I try to connect to a remote SQL server.

But when I run this code to connect to a remote SQL server from a Windows 2016 server which doesn't have any SQL installed, the server fails with sqlstate: 'IM002'

Could someone let me know what to do ? is there any dependencies I need to install?

My DevOps team is not allowing to install SQL studio in the specified box so is there any workaround ?:

Search for " ODBC Data Sources "

在此处输入图片说明

Now open it and goto driver tab:

在此处输入图片说明

You can see all the available drivers, as of now you are using "SQL Server Native Client 11.0" in your code:

Server={remote}; Database={Products}; Trusted_Connection=Yes;Driver={SQL Server Native Client 11.0};

Replace the driver with whatever available in your system.

Eg: if SQL server is available, use below connection string.

Server={remote}; Database={Products}; Trusted_Connection=Yes;Driver={SQL Server};

If you don't have ODBC Data source, then you have to install the SQL server NAtive 11 client from:

https://www.microsoft.com/en-us/download/confirmation.aspx?id=29065

click install instruction and navigate to:

在此处输入图片说明

Install the correct bit version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM