如何使用 activerecord、JDBC、JTDS 和集成安全性连接到 SQL Server

发布于 2024-09-01 17:46:57 字数 1615 浏览 6 评论 0原文

根据上面的内容,我尝试过:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抽个烟儿 2024-09-08 17:46:57

您可以尝试一起删除域、用户和密码吗?我使用 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.

装迷糊 2024-09-08 17:46:57

文件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,他的回答让我朝这个方向寻找)

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.:

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

(Big thanks to limc whose answer got me looking in this direction)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文