realbasic-nug
[Top] [All Lists]

Re: PostgreSQLDatabase Connections

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: PostgreSQLDatabase Connections
From: Norman Palardy <npalardy at great-white-software dot com>
Date: Wed, 30 Apr 2008 09:42:32 -0600
Authentication-results: mx.google.com; spf=pass (google.com: domain of realbasic-nug-bounces at lists dot realsoftware dot com designates 66.116.103.65 as permitted sender) smtp dot mail=realbasic-nug-bounces at lists dot realsoftware dot com
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <8259D3C7-7012-44FF-8D71-FC9FE80003D9 at no-no-badpuppy dot com> <082046DE-73EF-4340-8A3F-361B9B037AA9 at great-white-software dot com> <FE9621B0-4996-43A4-A8DB-ED8B3A6DC0C8 at no-no-badpuppy dot com>
On 30-Apr-08, at 9:22 AM, Robert Lawrence wrote:

> Norman:
>
> Thanks for the tip.    It brings to light another oddity.  Playing
> with this revised code (based on your idea), it looks like its
> connecting to the database that has the same name as the username.
> It's ignoring the DatabaseName completely.
>
>    Dim db as PostgreSQLDatabase
>    Dim rs as RecordSet
>
>    db = New PostgreSQLDatabase
>    db.host = fldHost.Text
>    db.port = Val(fldPort.Text)
>    ' db.DatabaseName = fldDatabase.Text
>    db.DatabaseName = "postgres"
>
>    db.Username = fldUser.Text
>    db.Password = fldPassword.Text
>
>    if db.connect then
>      MsgBox "Congratulations!  Communications with database verified."
>
>      rs = db.SQLSelect("select current_database()")
>      if  rs.RecordCount = 1 then
>        msgbox "Connected to " + rs.IdxField(1).StringValue
>      end if
>
>      db.close
>    else
>      MsgBox "Uh oh!  Something is wrong.  Check the server details and
> firewall settings."
>    end if
>
>
> Notice that I hardcoded .DatabaseName to "postgres".  I use my
> "rbtest" username when I run this code.  It tells me it connected to
> "rbtest" database.    I changed DatabaseName to "rbtest" and tried to
> login as postgres user.  It connected to the postgres database.
>
> Something is definitely weird here.
>

That's what my testing seemed to suggest as well
Running pgsql from my laptop to log in to a remote machine on my  
network I get the following

        macbookpro:~ npalardy$
        macbookpro:~ npalardy$  /usr/local/pgsql/bin/psql -h 10.0.1.201 -U  
npalardy -d test
        Welcome to psql 8.2.4 (server 8.2.3), the PostgreSQL interactive  
terminal.
        
        Type:  \copyright for distribution terms
               \h for help with SQL commands
               \? for help with psql commands
               \g or terminate with semicolon to execute query
               \q to quit
                
        test=> select current_database() ;
         current_database
        ------------------
         test
        (1 row)
        
        test=>

Using code much like yours

   dim dbConnection as PostgreSQLDatabase
   dim rs as RecordSet

   dbConnection = new PostgreSQLDatabase
   dbConnection.DatabaseName = "test"
   dbConnection.Host = "10.0.1.201"
   dbConnection.Port = 5432
   dbConnection.UserName = "npalardy"
   dbConnection.Password = ""

   // make the connection to the database with the supplied paramaters
   if dbConnection.connect = false then
     msgbox "not connected " + dbConnection.ErrorMessage
     return
   end if

   rs = dbConnection.SQLSelect("select current_database()")

   if not(rs is nil) then
     msgbox rs.IdxField(1).StringValue
   end if

when I run this I get my NOT CONNECTED dialogue saying "database  
"npalardy" does not exist


  
  
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>