views:

524

answers:

2

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]
+1  A: 

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.

limc
thanks limc - I tried this and updated the question
Rob
A: 

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)

Rob