I have a conversation in watson assistant and i want be able to call an action from IBM cloud function to make some query on my database (Azure). I'm not familiar with cloud function so this may be a dumb question, i don't understand how to make a connection with the database, i tried write some nodejs code but of course i'm wrong couse it return an "internal error". I also tried to write some code in python instead of nodejs. Again this is a dumb question so forgive me. Thank you!
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'my_host',
user: 'my_user',
password: 'my_psw',
database: 'my_db'
});
connection.connect();
rows = connection.query('my_query')
if (!err) {
console.log(typeof(rows));
console.log('The solution is: ', rows);
} else {
console.log(typeof(rows));
console.log('Error while performing Query.');
}
connection.end();
{
"error": "Internal error."
}
import pyodbc as pyodbc
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=my_server;DATABASE=my_db;UID=my_user;PWD=my_pwd')
cursor = conn.cursor()
sql = "my_sql"
cursor.execute(sql)
result = cursor.fetchall()
print(result)
csr = conn.cursor()
csr.close()
del csr
conn.close()
{
"error": "The action did not return a dictionary."
}