如何使用 activerecord、JDBC、JTDS 和集成安全性连接到 SQL Server
根据上面的内容,我尝试过:
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) 客户端虚拟机 1.6.0_18) [x86-java]
As per the above, I've tried:
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' )
.. and various other combinations.
Each time I get:
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)
If I try it with no user info:
establish_connection(:adapter => "jdbcmssql", :url => "jdbc:jtds:sqlserver://myserver/mydatabase")
I get this response:
net/sourceforge/jtds/jdbc/SQLDiagnostic.java:368:in `addDiagnostic': java.sql.SQLException: Login failed for user 'sa'. (NativeException)
Any tips? Thanks,
- 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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试一起删除域、用户和密码吗?我使用 Java 中的 JTDS 通过集成安全性连接到 SQL Server,我唯一指定的是服务器和数据库,因为它从我登录的计算机中获取其余的凭据。事实上,你也可以省略1433端口,因为我相信这是SQL Server的标准端口,因此可以省略。
Can you try removing domain, user and password all together? I connect to SQL Server through integrate security using JTDS in Java, and the only thing I specified is the server and database because it picks up the rest of the credential from the machine that I logged into. In fact, you can also omit the 1433 port because I believe that's the standard port for SQL Server, thus it can be omitted.
文件
ruby/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.6-java/lib/active_record/connection_adapters/jdbc_adapter.rb
第54行在没有用户时替换“sa”被给出。要解决此问题,请指定一个空白用户名,例如:(
非常感谢 limc,他的回答让我朝这个方向寻找)
File
ruby/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.6-java/lib/active_record/connection_adapters/jdbc_adapter.rb
line 54 substitutes 'sa' when no user is given.To work around this, specify a blank username, e.g.:
(Big thanks to limc whose answer got me looking in this direction)