[Vuejs]-How to make MSSQL connection using Node.js in vue.js frontend?

0👍

I solve this problem. As I am very new in this environment. Vue app renders client-side. I build server-side using template "webpack-ssr".
Here is more information about server-side rendering

here is my test code:

...

const sql = require('mssql')

...

// Create connection to database
const databaseConfig = {
  userName: 'USER_NAME',
  password: 'PASSWORD',
  server: 'SERVER_NAMECLOUDAPP.AZURE.COM',
  database: 'DATABASE',
  options: {
       encrypt: true // Use this if you're on Windows Azure
   }
}

...

Data conncetion:

// mssql connect for database 

sql.connect(databaseConfig, err => {

    // ... error checks

if (err) {
  console.log('error: ' + err)

} else {
  console.log('conencted')
}
// Query

new sql.Request().query('select 1 as number', (err , result) => {
    // ... error checks

       ...

    console.dir(result + ' hmmm ... not good')
})
})

...

Leave a comment