YagoDaniel92
3 years agoOccasional Contributor
Problems connecting to ADODB using Javascript and Firebird
I'm trying to connect to a FireBird database using getActiveXObject("ADODB.Connection") in Java Script, but the function is not returning the result of the query
function executeQuery(){
var withHeader = null
if (withHeader == null){
withHeader = false;
}
//Variáveis de conexão
var connection = getActiveXObject("ADODB.Connection");
connection.CommandTimeout = 2400;
var stringConnection = "DRIVER=Firebird/InterBase(r) driver;DBNAME=C:\\Resulth\\Banco\\RESULTH.FB;UID=sysdba;PWD=masterkey;DIALECT=3;";
var rs = getActiveXObject("ADODB.Recordset");
var result = new Array();
var i = 0;
for (i = 0; i <= 5; i++) {
try {
connection.Open(stringConnection);
rs.Open("select cidade, estado, codmunicipio from cidades where codcidade = '00001'", connection);
}
catch (e) {
Log.Message(e);
}
if (connection.State == 1) {
Log.Message("Query executada com sucesso!", "select cidade, estado, codmunicipio from cidades where codcidade = '00001'");
break;
}
else if (connection.State == 0) {
Log.Message("Query não foi executada com sucesso!", "select cidade, estado, codmunicipio from cidades where codcidade = '00001'");
Delay(3000);
}
}
if(connection.State == 0){
Log.Error('Não foi possivel executar a query');
}
try{
if (rs.eof){
resultado = null;
}
else{
while(!rs.eof){
result[i] = new Array();
if (withHeader){
if (i == 0){
for (var j = 0; j < rs.fields.Count; j++){
result[i][j] = rs.fields(j).name;
}
}else{
for (var j = 0; j < rs.fields.Count; j++){
result[i][j] = rs.fields(j).value;
}
rs.MoveNext();
}
}else{
for (var j = 0; j < rs.fields.Count; j++){
result[i][j] = rs.fields(j).value;
}
rs.MoveNext();
}
i++;
}
}
} catch(e){
result= null;
}
connection.close;
return result;
}
function returnResultQuery(){
var a;
a = executeQuery();
Delay(1);
}
Here's an image of the result
This same code works in JScript if I use "new ActiveXObject("ADODB.Connection");"
Here's the result in JScript
I need to run this code in Java Script