Forum Discussion

tuanvinh1008's avatar
tuanvinh1008
Contributor
4 years ago

doesn't work with Sys.OleObject("ADODB.Connection")

Hi all,
I wanna connect to my database, but it seems it doesn't work with Sys.OleObject("ADODB.Connection"). Here is my scripts

function DBInitialize() {
if (DatabaseName != "") {
DatabaseName = Settings.DB_DATABASENAME;
}
if (SQLServerName != "") {
SQLServerName = Settings.DB_SERVERNAME;
}
if (UserName != "") {
UserName = Settings.DB_USERNAME;
}
if (Password != "") {
Password = Settings.DB_PASSWORD;
}
if (ConnectionObject == null)
{
ConnectionObject= Sys.OleObject("ADODB.Connection")
}
}

function OpenDB(){
try {
ConnectionObject.ConnectionString = BuildConnectionString();
ConnectionObject.Open();
} catch (e){
Log.Error("Error running Openning a Database. See Additional Information for opening the database value: " + e.description)
}
}

function BuildConnectionString() {
DBInitialize();
ConnectionString = 'Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=';
ConnectionString = ConnectionString + DatabaseName;
ConnectionString = ConnectionString + ';Data Source=' + SQLServerName;
ConnectionString = ConnectionString + ';User Id=' + UserName;
ConnectionString = ConnectionString + ';Password=' + Password;
return ConnectionString;
}

function ReturnQueryRecordSetFromString(QueryString) {
OpenDB();
try
{
var RecordSet = ConnectionObject.Execute(aqConvert.VarToStr(QueryString));
return RecordSet;
}
catch (e)
{
Log.Error("Error running QueryString. See Additional Information for QueryString value: " + e.description, aqConvert.VarToStr(QueryString))
return aqObject.EmptyVariant;
}
ConnectionObject.Close();
}

My snippet code for execute

function TestDatabase() {
var querryString ="SELECT * FROM ACOUNT where NO = '111'";
var rec;
rec = DatabaseOperation.ReturnQueryRecordSetFromString(querryString);
Log.Message(rec);
}

 

it return the recordset empty, and I don't know how to check the connection status is open or ready to connect my Database.

 

 

Thanks,
Vinh