santana / ruby-informix

Ruby library for IBM Informix
http://ruby-informix.rubyforge.org
Other
17 stars 7 forks source link

#getting Informix::DatabaseError Incorrect password or user informix@[myservername] is not known on the database server. #6

Open wasimwaqia opened 1 year ago

wasimwaqia commented 1 year ago

Hello, I am trying to build a sample app with the stores demo database, I get the error "Informix::DatabaseError Incorrect password or user informix@[myservername] is not known on the database server."

I am able to connect to the server using irb and query data, however am unable to create any views using the gem 'ruby-informix', '~> 0.8.3' my database.yml config is

adapter: informix

server: my_servername

database: stores username: informix password: informix require 'informix' db=Informix.connect('stores', 'informix', 'informix')

is it possible to force the login with only the username rather than user@servername

I have also checked all my config and I can connect to the server using isql .

Thank you .

Screenshot 2023-04-08 at 3 21 28 AM

Screenshot 2023-04-08 at 3 21 51 AM

santana commented 1 year ago

Hello @wasimwaqia ! I'm taking a look.

santana commented 1 year ago

You can force a specific server when specifying the database, like this: stores@dbservername.

I'm guessing that irb is silently connecting to a different dbservername than the adapter you are using. You should see the same error in irb if you try to connect to stores@muharram. The question is, which dbserver is irb connecting to when succeeding?

There are many ways to get the Informix networking setup wrong... Double check /etc/hosts, $INFORMIXDIR/etc/sqlhosts as well as the shell environment that irb and the adapter are using.

Please let me know your findings.

wasimwaqia commented 1 year ago

Thank you very much for your reply ,

I want to let you know that both the informix server 14.X developers edition and the sdk are installed in the same server muharram

Screenshot 2023-04-08 at 4 20 15 PM

here is what i found out

  1. Replicating the rails server error I am able to replicate the rails server server in the irb if i add the @dbservername again when specifying the username (ie) username@dbservername , in my config which is informix@muhrram

Screenshot 2023-04-08 at 3 45 07 PM

Please look at the second part of the screenshot where the @dbservername is omitted the login is successful.

I have attached here a copy of the extract of the informix adapter config in my database.yml, i also noticed that if i change the server: [servername] settings , the configuration doesn't take effect at all I tried with following options a . server: muharram b. server: muharram_tcp c. server: muharram_odbc

Screenshot 2023-04-08 at 3 57 37 PM

The /etc/hosts file

Screenshot 2023-04-08 at 3 57 09 PM

The sqlhosts.dbservername file Screenshot 2023-04-08 at 3 56 42 PM

and my env variables releated to the informix Screenshot 2023-04-08 at 3 55 59 PM

Thanking you again.

santana commented 1 year ago

I see. Let me clarify that the dbservername, if you specify one, should be part of the first argument, the database name, not the user. The correct line should be:

db = new('stores@muharram', 'informix', 'informix')

Which leads me to think that the Rails adapter is doing it wrong or is misconfigured. What Rails adapter is it?

wasimwaqia commented 1 year ago

Thank you once again,

I am using both the activerecord and also ruby-infomix adapters

These are the list in the gem file for adding informix connections/adapters

Screenshot 2023-04-09 at 12 45 32 AM

My database.yml file has the following config for the adapter informix

development: <<: *default

database: db/development.sqlite3

adapter: informix server: muharram_tcp # it was muharram first , but trying out various options to get it working. database: stores username: informix password: informix require 'informix' db=Informix.connect('stores', 'informix', 'informix')

Screenshot 2023-04-09 at 1 15 22 AM

I am also following the instructions in the IBM developers hand book](https://www.redbooks.ibm.com/redbooks/pdfs/sg247884.pdf) from page 361 to 396

I am still new to RoR frame work and am trying to learn things.

I guess the server name is being populated from the env variable $INFORMIXSERVER

1st iteration with variable set to muharram

Screenshot 2023-04-09 at 12 48 29 AM setting the env to muharram

2nd iteration variable set to blank

Screenshot 2023-04-09 at 12 50 12 AM

Screenshot 2023-04-09 at 12 50 37 AM

3rd Iteration the variable set to muharram_odbc Screenshot 2023-04-09 at 12 51 47 AM

Screenshot 2023-04-09 at 12 54 42 AM

4th iteration setting the variable to some server name example - pronto

Screenshot 2023-04-09 at 12 56 16 AM

Screenshot 2023-04-09 at 1 03 27 AM

Thanks a lot

santana commented 1 year ago

It looks like there's a mistake in that book. You can see from the source code of the adapter that the server: setting in the configuration file is not used; only the database, user and password:

https://github.com/santana/activerecord-informix-adapter/blob/9bb3b6dfc59a322a23e1f3e52fb16852c69c3004/lib/active_record/connection_adapters/informix_adapter.rb#L32-L43

    def self.informix_connection(config) #:nodoc:
      require 'informix' unless self.class.const_defined?(:Informix)
      require 'stringio'

      config = config.symbolize_keys

      database    = config[:database].to_s
      username    = config[:username]
      password    = config[:password]
      db          = Informix.connect(database, username, password)
      ConnectionAdapters::InformixAdapter.new(db, logger)
    end

If you need to specify a server, include it in the database name. In this case it would look like this: stores@muharram_tcp or stores@muharram.

Can you give that a try in irb and Ruby on Rails?

wasimwaqia commented 1 year ago

I tried the following 1 update the informix adapter in database.yml file - remove the server: muharram

  1. set database: stores

Output Rails Server - error Error details - Informix::DatabaseError Incorrect password or user informix@muharram is not known on the database server.

irb setting db = new('stores') output success => #<Informix::Database:0x00007f79b41ac220 @version=#<struct Struct::IfxVersion server_type="IBM Informix Dynamic Server DE", major="14", minor="10", level="F", os="C5", full="IBM Informix Dynamic Server Version 14.10.FC5DE">>

irb setting db = new('stores@muharram') output success => #<Informix::Database:0x00007f79b421c818 @version=#<struct Struct::IfxVersion server_type="IBM Informix Dynamic Server DE", major="14", minor="10", level="F", os="C5", full="IBM Informix Dynamic Server Version 14.10.FC5DE">>

irb setting db = new('stores@muharram_odbc') output success => #<Informix::Database:0x00007f79b3f47228 @version=#<struct Struct::IfxVersion server_type="IBM Informix Dynamic Server DE", major="14", minor="10", level="F", os="C5", full="IBM Informix Dynamic Server Version 14.10.FC5DE">>

irb setting db = new('stores@muharram_tcp') output success => #<Informix::Database:0x00007f79b3f58730 @version=#<struct Struct::IfxVersion server_type="IBM Informix Dynamic Server DE", major="14", minor="10", level="F", os="C5", full="IBM Informix Dynamic Server Version 14.10.FC5DE">>

  1. a. set the database: stores@muharram in database.yml file output: error error details Informix::DatabaseError Incorrect password or user informix@muharram is not known on the database server.

irb setting db = new('stores@muharram') output success => #<Informix::Database:0x00007f93a8062e60 @version=#<struct Struct::IfxVersion server_type="IBM Informix Dynamic Server DE", major="14", minor="10", level="F", os="C5", full="IBM Informix Dynamic Server Version 14.10.FC5DE">>

2.b. set the database: stores@muharram_tcp in database.yml file output: error error details Informix::DatabaseError Incorrect password or user informix@localhost[muharram] is not known on the database server.

irb setting db = new('stores@muharram_tcp') output suceess

db = new('stores@muharram_tcp') => #<Informix::Database:0x00007f0f55cd69a8 @version=#<struct Struct::IfxVersion server_type="IBM Informix Dynamic Server DE", major="14", minor="10", level="F", os="C5", full="IBM Informix Dynamic Server Version 14.10.FC5DE">>

2.c. set the database: stores@muharram_odb in database.yml file output: error error details Informix::DatabaseError Incorrect password or user informix@localhost[muharram] is not known on the database server.

irb setting db = new ('stores@muharram_odbc) output suceess

db = new('stores@muharram_odbc') => #<Informix::Database:0x00007fa2e38bf488 @version=#<struct Struct::IfxVersion server_type="IBM Informix Dynamic Server DE", major="14", minor="10", level="F", os="C5", full="IBM Informix Dynamic Server Version 14.10.FC5DE">>

summary rails adapter within rails server errors with the message Error details - Informix::DatabaseError Incorrect password or user informix@muharram is not known on the database server. . only the hostdetails changes from @muharram to @localhost[muharram] when i add @servername suffix to database: in other words irb works for all the iterations where as the rails adapter does not work.

I am able to run any *.rb files from ruby example i create a ifx_metadata.rb under config directory

load the informix driver

require 'informix'

Connect to the database

db = Informix.connect(ARGV[0])

print database information

print "Connected to #{db.version}\n" db.columns(ARGV[1]).each { |name| name.each {|elem| print " #{elem[0]} #{elem[1]}\n"} } db.close

I can run it with ruby ifx_metadata.rb stores state output is as below Screenshot 2023-04-09 at 1 42 05 PM

but when i run rails s i get the following error

Screenshot 2023-04-09 at 1 00 55 PM

Screenshot 2023-04-09 at 12 41 54 PM

santana commented 1 year ago

According to the error message, the adapter is attaching the server name to the username, which is wrong. This adapter however never does that. Are you sure that's the one you're using? You can try finding that file in Rails and edit it to get more debug information.

wasimwaqia commented 1 year ago

I have now reinstalled the adapter , however i find something strange when i try to read the adapter settings from irb my adapter settings in the database.yml file is as follows # development:

<<: *default

database: db/development.sqlite3

adapter: informix database: stores@muharram username: informix password: informix
require 'informix' db = Informix.connect('stores')

Screenshot 2023-04-10 at 11 40 44 AM

when try to query the database.yml configuration in the irb I see some strange output for the variable password the output i get is => "informix require 'informix' db = Informix.connect('stores')" Please see the screenshot below for all my queries for the variables db, dbname, user and password

Screenshot 2023-04-10 at 11 26 14 AM

I tried even separating the lines password and require password: informix

     require 'informix'
     db = Informix.connect('stores')

when i do this my query for password in irb returns => "informix\nrequire 'informix' db = Informix.connect('stores')"

Screenshot 2023-04-10 at 11 45 44 AM

if i try to alter the adapter settings i get entirely a different error

if i change my database.yml as below

# development:

<<: *default

database: db/development.sqlite3

adapter: informix database: stores@muharram username: informix password: informix
# require 'informix' db = Informix.connect('stores')

Screenshot 2023-04-10 at 11 46 20 AM

The error i get goes something like this Puma caught this error: Cannot load database configuration: YAML syntax error occurred while parsing /var/www/projects/rails/01storeapp/mystore/config/database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (): did not find expected key while parsing a block mapping at line 15 column 3 (RuntimeError)

screenshot below

Screenshot 2023-04-10 at 11 36 33 AM

from this my conclusion is that the configuration is reading a wrong password and the possible solution would be to isolate the password parameter value and the require parameter

is there a possibility to get the password and the require parameters separated?

Thank you

santana commented 1 year ago

Indeed, these lines DO NOT belong to the configuration file:

require 'informix'
db = Informix.connect('stores')

Delete them from the configuration file.

wasimwaqia commented 1 year ago

If i delete the require 'informix' db = Informix.connect('stores')

I get the error : NotImplementedError NotImplementedError

please let me know In which file should i include this parameters to connect to the db

Screenshot 2023-04-10 at 11 36 58 PM

Thank you Abdul

santana commented 1 year ago

This code:

require 'informix'
db = Informix.connect('stores')

is not meant to be included in any configuration file. It is definitely not expected if you are using this Ruby on Rails adapter for Informix: https://github.com/santana/activerecord-informix-adapter

I showed above how the configuration file is used, here: https://github.com/santana/activerecord-informix-adapter/blob/9bb3b6dfc59a322a23e1f3e52fb16852c69c3004/lib/active_record/connection_adapters/informix_adapter.rb#L32-L43

No code is expected; only configuration.

santana commented 1 year ago

Take in account that this adapter https://github.com/santana/activerecord-informix-adapter is old and it's more likely not compatible with newer versions of Ruby on Rails.