Postgresql & xojo cloud

Urgent help!

For what reason does it not send an error message?

The following code works on my Mac, but not on XOJO CLOUD.
Pass everything OK, in the login, it never finds any user.

I will appreciate the help.

if DBlink = nil then
  DBLink = New PostgreSQLDatabase
 
  #If TargetXojoCloud Then
    ' CLOUD DB
    DBlink.host = "localhost"
    DBlink.Port = 5432
    'DBlink.DatabaseName = "MEDICS_DB"
    DBlink.DatabaseName = "postgres"
    DBlink.Username = "dbadmin"
    DBlink.Password = "Password"
  #Else
    ' LOCAL DB
    DBlink.host = "localhost"
    DBlink.Port = 5432
    DBlink.DatabaseName = "MEDICS_DB"
    DBlink.Username = "postgres"
    DBlink.Password = "Password"
  #EndIf
 
  If  DBlink.Connect = false Then
    Messagebox ("Off line""+EndOfLine+EndOfLine+DBlink.ErrorMessage)
  Else
    lConnected = True
  End If
end if

Wouldn’t that indicate that it’s working on Xojo Cloud? You only show a message if there’s an error.

1 Like

Can you please post the select where you are retrieving your user? Note that Postgres is case-sensitive. You might have built your table differently in dev and prod. Such slight differences can easily be overlooked.

It is right, Jeannot. Postgres is case-sensitive.

What strikes me is that it works perfectly with my local database. Running XOJO locally.
But it does not work the same in XOJO Cloud.

Greg, an apology for not explain well.
Indeed, XOJO Cloud works perfectly.

The problem, I do not know what is happening in this particular issue: when it makes a query to verify if the user exists.

The code does not send any errors. But it never finds the user, knowing that it exists in the table.

Note.- it works perfectly with my local database.

Look this code:

if DBlink = nil then
DBLink = New PostgreSQLDatabase

      #If TargetXojoCloud Then
    ' CLOUD DB
    DBlink.host = "localhost"
    DBlink.Port = 5432
    'DBlink.DatabaseName = "MEDICS_DB"
    DBlink.DatabaseName = "postgres"
    DBlink.Username = "dbadmin"
    DBlink.Password = "XXXXXXXXXXXXXX"

    Var sql As String
    sql = "SELECT * FROM Tab_Users where cUser_Name=$1;"
   
    Var ps As PostgreSQLPreparedStatement
    Var rs As RecordSet
    ps = Session.DBlink.Prepare(sql)
    ps.Bind(0, "Loreto_R")
    ps.SQLExecute

    if  Session.DBlink.Connect = true then
      rs = ps.SQLSelect
      Var Getpass As String = rs.Field("cUser_Password")
      MessageBox(Getpass)
    else
      Messagebox ("Error")
    end if

  #Else
    ' LOCAL DB
    DBlink.host = "localhost"
    DBlink.Port = 5432
    DBlink.DatabaseName = "MEDICS_DB"
    DBlink.Username = "postgres"
    DBlink.Password = "XXXXXXXXXXXXXX"
   
  #EndIf

Is Tab_Users a table in your database?

Yes. Tab_Users is a table.
Everything is new. I use WEB2 and a new XOJO Cloud.

which of your two servers is this on?

which of your two servers is this on?
In XOJO Cloud

Yes, but you have two different Xojo Cloud servers. One in NYC and one in SFO. Which one is it?

Sorry.
San Francisco.
Please don’t hang me. For using MessageBox.

I’m just logging into the server to make sure there’s nothing wrong.

Just sent you a private message.

Thanks !
Did you observe any error ?

ok, so in your code, you are telling it to use the “postgres” database, but that one is completely empty (as it should be because it’s for postgresql to manage itself.

'DBlink.DatabaseName = "MEDICS_DB"
DBlink.DatabaseName = "postgres"

in your code, switch to this:

DBlink.DatabaseName = "MEDICS_DB"
'DBlink.DatabaseName = "postgres"

I just ran your query in my PostgreSQL client and it works just fine.

Also, in the future, please be more careful about pasting code to the forum which contains passwords. I replaced yours with X’s in your code example.

2 Likes

:open_mouth:

True. I shouldn’t have.

1 Like

Greg: " ok, so in your code, you are telling it to use the “postgres” database, but that one is completely empty (as it should be because it’s for postgresql to manage itself.

'DBlink.DatabaseName = "MEDICS_DB"
DBlink.DatabaseName = "postgres"

in your code, switch to this:

DBlink.DatabaseName = "MEDICS_DB"
'DBlink.DatabaseName = "postgres"

I just ran your query in my PostgreSQL client and it works just fine."

I did this, to test if I can connect to one base or another.
I made the change you suggest. Xojo cannot connect.
He sends me an error.
"FATAL: database "MEDICS_DB" does not exist"

If DBlink = nil Then
  DBLink = New PostgreSQLDatabase
  MessageBox ("1. Dblink no es nulo")
 
  #If TargetXojoCloud Then
    MessageBox("2. Cloud")
    ' CLOUD DB
    DBlink.host = "localhost"
    DBlink.Port = 5432
    DBlink.DatabaseName = "MEDICS_DB"
    DBlink.Username = "dbadmin"
    DBlink.Password = "Password"
   
    Try
      Session.DBlink.Connect
    Catch Err As DatabaseException
      Messagebox(Err.Message)
    End Try
   
    Var sql As String
    sql = "SELECT * FROM Tab_Users where cUser_Name=$1;"
   
    Var ps As PostgreSQLPreparedStatement
    Var rs As RecordSet
    ps = Session.DBlink.Prepare(sql)
    ps.Bind(0, "Loreto_R")
    ps.SQLExecute
    Messagebox("3. Exec")
   
    If  Session.DBlink.Connect = true then
      MessageBox("True")
      rs = ps.SQLSelect
      Var Getpass As String = rs.Field("cUser_Password")
      MessageBox("Final")
      MessageBox(Getpass)
    Else
      Messagebox ("Error !!!!")
    End if
   
  #Else
    MessageBox("Local")
    ' LOCAL DB
    DBlink.host = "localhost"
    DBlink.Port = 5432
    DBlink.DatabaseName = "MEDICS_DB"
    DBlink.Username = "postgres"
    DBlink.Password = "Password"
  #EndIf
 
  If  DBlink.Connect = false Then
    Messagebox ("Se ha perdido o no se ha podido establecer la conexiĂłn con la base de datos."+EndOfLine+EndOfLine+"Revise su conexiĂłn a internet."+EndOfLine+EndOfLine+DBlink.ErrorMessage)
  Else
    MessageBox("Conectado")
    lConnected = True
  End If
End if

Thanks to Greg and Jeannot, for your answers.

The problem was resolved.

1 Like

Can you indicate the REAL solution, rather than your final thanks as the solution? It helps us all.

1 Like