使用以下代码:
require 'activerecord-jdbc-adapter'
require 'activerecord-jdbcmssql-adapter'
require_relative 'sqljdbc42.jar'
ActiveRecord::Base.establish_connection(
:adapter => 'jdbcmssql',
:driver => 'com.microsoft.sqlserver.jdbc.SQLServerDriver',
:username => 'pcp_admin',
:password => 'pcp_admin01',
:port => 1021,
:database => 'pcp',
:url => 'jdbc:sqlserver://OHNALWBD0145.nwie.net',
)
@connection = ActiveRecord::Base.connection
这是要使用的所有正确信息。但是,当我尝试运行它时,我收到以下错误:
ActiveRecord::JDBCError: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host OHNALWBD0145.nwie.net, port 1433 has failed. Error: "Connection refused: no further information. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
我发现此错误消息特别奇怪,因为我已将端口输入方法1021,而不是1433.我不知道为什么它尝试使用端口1433.我知道这是默认端口SQLServer,但我应该重写,或者我认为。