MSSQL connection error - tedious module

Hello,

I’m trying to connect to my mssql database with code:

const Knex = require('knex')

  const getNameByEmailAddress = async () => {
    const knex = await Knex({
      client: 'mssql',
      //connection: 'postgres://postgres:qazwsx@localhost:5432/bp8'
      connection: {
        connectionString: 'Initial Catalog=PeopleList;Data Source=localhost\\SQLEXPRESS;Integrated Security=SSPI;'
      }
    })

    const users = await knex('dbo.Person')
      .select('Name')
      .where({ Email: temp.user_email })
    console.log(users)
    temp['user_name_2'] = users
  }

  return getNameByEmailAddress()

when I try to execute I get this error:

Can you please advice if my code is ok and how to download and install tedious package?

Thank you.

Hi @kyon84,

Is this piece of code running in an action ? From the Knex docs, it seems like to connect to MsSql (or any other Sql db) you need to have the appropriate database library installed as dependency, in your case (mssql). Botpress comes with Postgres and Sqlite support.

I haven’t tested but I believe that if you’re running botpress with binaries and want to connect to any other SQL db in your actions you’ll have to build a custom botpress module which has mssql as dependency and write your actions in that module.

Another way around would be to run botpress sources and install msSql packaged as a botpress dependency.

Don’t loose hope though, we’re soon introducing http actions, where you can write your actions in a simple webserver in the language of your choice (in which you can manage your dependencies easily without having to write a custom module or build the whole botpress sources)

Hope this level of details helps.

Hello,

thank for reply!

Yes code runs inside of an action.

Can you tell what is the easiest way how to establish connection? Should I go for custom botpress module? I’m not very skilled so far :slight_smile: Is there any step by step procedure for this?

Thanks