cancel
Showing results for 
Search instead for 
Did you mean: 

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

tuanvinh1008
Contributor

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

4 REPLIES 4
vinniew
Staff

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

Hi @tuanvinh1008 

 

Hope you are well. 

 

Have you checked all the requirements for connecting to a DB? 

 

One important step is that TestComplete uses database drivers that have the same bitness.

 

Check that both the TC and the DB drivers have the same 

 

See 

https://support.smartbear.com/testcomplete/docs/testing-with/working-with-external-data-sources/data...

 

KR 

Vincent 

tuanvinh1008
Contributor

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

Yes, TC and  DB drivers are them same bitness it is 64 bits

vinniew
Staff

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

tuanvinh1008
Contributor

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

Hi viniew,

Do we have another ways that doesn't need to create DSN? As I remember we don't need to create a DSN link on the developer site?

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors