[英]“No connection pool for UserActionEvent” when connecting to SqlServer
I have a simple ruby script. 我有一个简单的ruby脚本。
I need connection SqlServer and Mysql. 我需要连接SqlServer和Mysql。 I use gem 'mysql2' connection is successfully,but i use gem 'tiny_tds' and 'activerecord-sqlserver-adapter' is failed. 我使用gem'mysql2'连接成功,但我使用gem'mino_tds'和'activerecord-sqlserver-adapter'失败。 my error: 我的错误:
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:570:in `retrieve_connection': No connection pool for UserActionEvent (ActiveRecord::ConnectionNotEstablished)
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-4.2.7.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-4.2.7.1/lib/active_record/connection_handling.rb:87:in `connection'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-4.2.7.1/lib/active_record/querying.rb:39:in `find_by_sql'
from D:/work/rails_obj/export_data/business/tear_bb.rb:49:in `main'
from export_data.rb:22:in `main'
from export_data.rb:28:in `<main>'
my gemfile: 我的宝石文件:
gem 'mysql2', '0.4.4'
gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter'
gem 'require_all', '1.3.3'
gem 'activerecord', '~>4.2.1'
my gemfile.lock: 我的gemfile.lock:
GEM
remote: https://gems.ruby-china.org/
specs:
activemodel (4.2.7.1)
activesupport (= 4.2.7.1)
builder (~> 3.1)
activerecord (4.2.7.1)
activemodel (= 4.2.7.1)
activesupport (= 4.2.7.1)
arel (~> 6.0)
activerecord-sqlserver-adapter (4.2.15)
activerecord (~> 4.2.1)
activesupport (4.2.7.1)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
builder (3.2.2)
i18n (0.7.0)
json (1.8.3)
mini_portile2 (2.1.0)
minitest (5.9.0)
mysql2 (0.4.4-x64-mingw32)
require_all (1.3.3)
thread_safe (0.3.5)
tiny_tds (1.0.4-x64-mingw32)
mini_portile2 (~> 2.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
PLATFORMS
x64-mingw32
DEPENDENCIES
activerecord (~> 4.2.1)
activerecord-sqlserver-adapter
mysql2 (= 0.4.4)
require_all (= 1.3.3)
tiny_tds
BUNDLED WITH
1.12.5
my code: 我的代码:
class AnalyticsBase < ActiveRecord::Base
db_config = YAML::load File.open 'configs/sqlserver.yml'
establish_connection = db_config['Analytics']
self.abstract_class = true
end
class UserActionEvent < AnalyticsBase
self.table_name = 'UserActionEvent'
end
class TearBb
def self.main
sql3 = "select top 5 * from UserActionEvent"
UserActionEvent.find_by_sql sql3
end
end
TearBb.main
configs/sqlserver.yml: CONFIGS / sqlserver.yml:
comm_config: &comm
adapter: sqlserver
encoding: utf8
Analytics:
<<: *comm
host: myhost
port: myport
database: mydatabase
username: myusername
password: mypasword
timeout: 60000
my system: windows 7 我的系统:Windows 7
How do I deal with this problem? 我该如何处理这个问题? thanks! 谢谢!
Not sure what the use case is here, but nonetheless I think the issue you are having is related to the use of the establish_connection
method (from ActiveRecord::Base
which you should be passing an argument to (instead of assigning it) 不确定这里的用例是什么,但是我认为你遇到的问题与使用establish_connection
方法有关(来自ActiveRecord::Base
,你应该传递一个参数(而不是分配它)
establish_connection = db_config['Analytics']
should become: 应成为:
establish_connection db_config['Analytics']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.