无法在我的ruby脚本中建立ActiveRecord连接

时间:2018-08-24 13:42:59

标签: sql-server ruby activerecord

我正在尝试与我的ruby脚本建立Active Record连接,但不断出现以下错误:

18:08:41,360 ERROR [stderr] (ServerService Thread Pool -- 331) Attempting to kil
    l Elasticsearch process left over from previous execution: 4584
    18:08:41,360 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 33
    1) MSC000001: Failed to start service jboss.undertow.deployment.default-server.d
    efault-host./apiman-es: org.jboss.msc.service.StartException in service jboss.un
    dertow.deployment.default-server.default-host./apiman-es: java.lang.RuntimeExcep
    tion: java.lang.RuntimeException: java.io.IOException: Cannot run program "kill"
    : CreateProcess error=2, The system cannot find the file specified
            at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1
    .run(UndertowDeploymentService.java:84)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:51
    1)
            at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
    java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
    .java:617)
            at java.lang.Thread.run(Thread.java:748)
            at org.jboss.threads.JBossThread.run(JBossThread.java:320)
    Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.io.IOExc
    eption: Cannot run program "kill": CreateProcess error=2, The system cannot find
     the file specified
            at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManag
    erImpl.java:241)
            at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.s
    tartContext(UndertowDeploymentService.java:99)
            at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1
    .run(UndertowDeploymentService.java:81)
            ... 6 more
    Caused by: java.lang.RuntimeException: java.io.IOException: Cannot run program "
    kill": CreateProcess error=2, The system cannot find the file specified
            at io.apiman.distro.es.Bootstrapper.contextInitialized(Bootstrapper.java
    :96)
            at io.undertow.servlet.core.ApplicationListeners.contextInitialized(Appl
    icationListeners.java:187)
            at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManag
    erImpl.java:205)
            at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManag
    erImpl.java:174)
            at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.cal
    l(ServletRequestContextThreadSetupAction.java:42)
            at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(Context
    ClassLoaderSetupAction.java:43)
            at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAct
    ion.lambda$create$0(SecurityContextThreadSetupAction.java:105)
            at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi
    ce$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:
    1508)
            at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi
    ce$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:
    1508)
            at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi
    ce$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:
    1508)
            at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi
    ce$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:
    1508)
            at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManag
    erImpl.java:239)
            ... 8 more
    Caused by: java.io.IOException: Cannot run program "kill": CreateProcess error=2
    , The system cannot find the file specified
            at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
            at java.lang.Runtime.exec(Runtime.java:620)
            at java.lang.Runtime.exec(Runtime.java:450)
            at java.lang.Runtime.exec(Runtime.java:347)
            at io.apiman.common.es.util.ApimanEmbeddedElastic.checkForDanglingProces
    ses(ApimanEmbeddedElastic.java:139)
            at io.apiman.common.es.util.ApimanEmbeddedElastic.start(ApimanEmbeddedEl
    astic.java:89)
            at io.apiman.distro.es.Bootstrapper.contextInitialized(Bootstrapper.java
    :94)
            ... 19 more
    Caused by: java.io.IOException: CreateProcess error=2, The system cannot find th
    e file specified
            at java.lang.ProcessImpl.create(Native Method)
            at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
            at java.lang.ProcessImpl.start(ProcessImpl.java:137)
            at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
            ... 25 more

下面列出了我的连接文件,我不确定自己做错了什么。

Traceback (most recent call last):
        10: from ./main.rb:2:in `<main>'
         9: from /home/daveomcd/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
         8: from /home/daveomcd/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
         7: from /mnt/c/Users/mcdonaldd/Documents/Ruby Projects/nfl_ngs/config/initializers/initializer.rb:17:in `<top (required)>'
         6: from /home/daveomcd/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_handling.rb:60:in `establish_connection'
         5: from /home/daveomcd/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:950:in `establish_connection'
         4: from /home/daveomcd/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/connection_specification.rb:190:in `spec'
         3: from /home/daveomcd/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/connection_specification.rb:203:in `rescue in spec'
         2: from /home/daveomcd/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/connection_specification.rb:203:in `raise'
         1: from /home/daveomcd/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/connection_specification.rb:203:in `exception'
/home/daveomcd/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/errors.rb:84:in `initialize': wrong number of arguments (given 1, expected 2) (ArgumentError)

2 个答案:

答案 0 :(得分:1)

ActiveRecord连接需要连接适配器来适当地转换SQL以适合与AR交互的数据库。 ActiveRecord附带了一组本地适配器,包括“ mysql2”,“ postgres”和“ sqlite3”,但是在这种情况下,您正在使用MSSQL(如连接配置中的adapter: 'sqlserver'所示),它将需要外部适配器。

在这种情况下,外部适配器是activerecord-sqlserver-adapter gem。

可以使用gem install activerecord-sqlserver-adapter来安装它,然后只需像处理其他gem一样在文件中要求它即可。

尽管该gem没有明确的依赖性(ActiveRecord之外),您将需要指定一种连接模式(或使用默认的:dblib)。到目前为止,使用默认设置是最简单的方法(而且我从未遇到过任何问题),但是此模式确实需要包含tiny_tds gem(您已经需要)

答案 1 :(得分:0)

可能您必须按照我们的朋友所说的来安装activerecord-sqlserver-adapter。默认情况下,sqlite附带有ruby on rails。尝试安装rubymine IDE,它将帮助您使用界面配置数据库。看下面:

Configuration screen