Forum Discussion
10 Replies
- AlexKaras
Champion Level 1
Hi,
In addition to Robert's reply: https://www.connectionstrings.com/postgresql/ might provide you with the samples of connection strings.
- astContributor
Hi there
I got a connection:
1. Installed an appropriate ODBC driver (same version as postgreSQL-DB) from https://www.postgresql.org/ftp/odbc/versions/msi/
2. Got the connection string from https://www.connectionstrings.com/postgresql-odbc-driver-psqlodbc/
Example of my code:
function letsTest() {
Log.Message(select("select * from config where configkey='smtpHost'", "configstring"));
}
function createAdoQuery(sqlStatement) {
var query = ADO.CreateADOQuery();
query.ConnectionString = "Driver={PostgreSQL ANSI};Server=<MyIP>;Port=<MyPort>;Database=<MyDB>;Uid=<MyDbUsername>;Pwd=<MyDbPassword>;";
query.SQL = sqlStatement;
return query;
}
function select(sqlStatement, columnName) {
var query = createAdoQuery(sqlStatement);
query.Open();
var result;
var noOfRecords = query.RecordCount;
if (noOfRecords == 1) { // I only expect one result
query.First();
while (! query.EOF)
{
result = query.FieldByName(columnName).Value;
query.Next();
}
} else {
Log.Error("There are " + noOfRecords + " records instead of one ?!")
}
query.Close();
return result;
}Have fun!
- maxtesterContributor
Hi,
I am facing the same problem. I have installed the driver and I also have a connection string that should work (based on the link). The Problem is, that I get an error message: "Unspecified error".
I don't know what to do with this message. The database is online, users are correct and I can create an ODBC Data Source. Can anybody help me out?
- tristaanogreEsteemed Contributor
There is no specific support for postgres DB in TestComplete. In order to connect to the database, you will need to utilize the ADO objects available in TestComplete and construct queries and connection strings via code. See https://support.smartbear.com/testcomplete/docs/testing-with/advanced/working-with-external-data-sources/databases/index.html for general information to get you started.
- AlexKaras
Champion Level 1
<Erroneous post - removed>
- nitingambhir88Occasional Contributor
With the help of above thread, I am successfully able to get the results from my database. But, it provides with only one result at one time, as the code states -- if (noOfRecords == 1) .
My query gives multiple rows, and hence the error. What could be the best possible solution for this.
Also, i want to email the results of this query. Please suggest.
Thanks,
-Nitin
- nitingambhir88Occasional Contributor
Can anybody respond to the question i mentioned above?