如何使用activerecord,JDBC,JTDS和Integrated Security连接到SQL Server

时间:2010-05-17 23:59:09

标签: sql-server activerecord jdbc jruby jtds

根据以上所述,我尝试过:

establish_connection(:adapter  => "jdbcmssql", :url => "jdbc:jtds:sqlserver://myserver:1433/mydatabase;domain='mynetwork';", :username => 'user', :password=>'pass' )
establish_connection(:adapter  => "jdbcmssql", :url => 'jdbc:jtds:sqlserver://myserver:1433/mydatabase;domain="mynetwork";user="mynetwork\user"' )
establish_connection(:adapter  => "jdbcmssql", :url => "jdbc:jtds:sqlserver://myserver:1433/mydatabase;domain='mynetwork';", :username=>'user' )
establish_connection(:adapter  => "jdbcmssql", :url => "jdbc:jtds:sqlserver://myserver:1433/mydatabase;domain='mynetwork';integratedSecurity='true'", :username=>'user' )

..以及其他各种组合。

每次我得到:

net/sourceforge/jtds/jdbc/SQLDiagnostic.java:368:in `addDiagnostic': java.sql.SQLException: Login failed for user ''. The user is not associated with a trusted SQL Server connection. (NativeException)

如果我尝试没有用户信息:

establish_connection(:adapter  => "jdbcmssql", :url => "jdbc:jtds:sqlserver://myserver/mydatabase") 

我收到了这个回复:

net/sourceforge/jtds/jdbc/SQLDiagnostic.java:368:in `addDiagnostic': java.sql.SQLException: Login failed for user 'sa'. (NativeException)

任何提示?谢谢,

  • activerecord(2.3.5)
  • activerecord-jdbc-adapter(0.9.6)
  • activerecord -jdbcmssql-adapter(0.9.6)
  • jdbc-jtds(1.2.5)
  • jruby 1.4.0(ruby 1.8.7 patchlevel 174)(2009-11-02 69fbfa3)(Java HotSpot(TM)Client VM 1.6.0_18)[x86-java]

2 个答案:

答案 0 :(得分:1)

您可以尝试一起删除域名,用户名和密码吗?我通过Java中的JTDS集成安全性连接到SQL Server,我唯一指定的是服务器和数据库,因为它从我登录的机器中获取了其余的凭据。实际上,您也可以省略1433端口,因为我认为它是SQL Server的标准端口,因此可以省略。

答案 1 :(得分:0)

当没有给出用户时,

文件ruby/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.6-java/lib/active_record/connection_adapters/jdbc_adapter.rb第54行替换'sa'。

要解决此问题,请指定空白用户名,例如:

establish_connection(:adapter  => "jdbcmssql", :url => "jdbc:jtds:sqlserver://myserver/mydatabase", :username=>'') 

(非常感谢limc的回答让我朝这个方向看)