On 12/12/2010 5:53 AM, dave lilley wrote:
Below is the initialization method i use and the results i get below that.
  def initialize(*arg)
    @path = "/logs"
 puts 'in DB connection initialize'
    @log = Logger.new("#...@path}db <mailto:#...@path%7ddb> - info.log")
    @log.level = Logger::DEBUG

    @log.debug('initialing the DB access!')

    if arg[0] == 'local'
@db = Sequel.connect(:adapter => 'mysql', :localhost => 'localhost', :database => 'test', :user => 'dave', :password => 'test')
      # local
    else
 puts 'in remote side'
@db = *Sequel.mysql.connect*(:host => 'remote.co.nz <http://remote.co.nz>', :database => 'remote', :user => "my_name", :password => "2010") # Mysql.new(hostname, username, password, databasename) <<< success before using teh mysql gem directly. # @db = Mysql.new('remote.co.nz <http://remote.co.nz>', "my_name", "2010",'remote')
      # remote
    end
    Thread.new{loop{sleep 60; DB.get(1)}}
 rescue Sequel::DatabaseError
@log.debug("An error occurred\nError code: #{Sequel}\nError message: #{Sequel.to_s}")
    ensure
      @log.debug("DB closed!")
      # @db.disconnect if @db

  end
  def get_all_acccodes
    @log.debug('getting all account codes')
row = @db[:cust_data].filter(:closed => 0, :contract => 0) # 1 = true account is CLOSED, 0 means it's OPEN # @db.query('select * from cust_data') <<< successfully got customer data returned
  end
a = Dopen.new 'remote'
ans = a.get_all_acccodes # return all customer data - simple!

ans.each{|e| puts e}
C:\monitoring screen>ruby -rubygems sequel1.rb
in DB connection initialize
in remote side
C:/Ruby187/lib/ruby/gems/1.8/gems/sequel-3.18.0/lib/sequel/adapters/mysql.rb:112
:in `real_connect': Access denied for user 'dave'@'localhost' <mailto:%27dave...@%27localhost%27> (using password: N
O) (Mysql::Error)
from C:/Ruby187/lib/ruby/gems/1.8/gems/sequel-3.18.0/lib/sequel/adapters
/mysql.rb:112:in `connect'
        from sequel1.rb:21:in `initialize'
        from sequel1.rb:169:in `new'
        from sequel1.rb:169
C:\monitoring screen>


Why are you using a different connect method for local and remote. The connect you are using for "local" looks (almost) correct, the "remote" one is just wrong. All you need to do is use the same construct as for local, but change the host and perhaps username & password?

LOCAL
@db = Sequel.connect(:adapter => 'mysql', :host => 'localhost', :database => 'test', :user => 'dave', :password => 'test')

REMOTE
@db = Sequel.connect(:adapter => 'mysql', :host => 'remote.co.nz', :database => 'test', :user => 'dave', :password => 'test')


The error you are getting is not from Sequel but from mysql itself, basically saying the user 'dave' is not allowed to connect to 'localhost'. This will be from your *local* mysql denying that user access. If you want to connect to your locally installed mysql with the username 'dave' then you are going to have to create a user called 'dave'@'localhost' within your local mysql.

You might *think* you are connecting remotely, but the error message says otherwise. You really need to get your connection parameters right.

http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html

Cheers,
Gary,

--
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to