I got it working. Details for DSN-less connections:
1. Driver parameters keys must be in uppercase;
2. The connect(server) method in odbc.rb converts all server_opts into
driver parameters. There are some that don't concern ODBC
like :disconnection_proc and :single_threaded. These were not strings,
and were crashing. These can either be ignored or just stringified. I
chose the latter for simplicity.
This was the driver with the minimum fields required, tested using
ODBC directly:
=> #<ODBC::Driver:0x15a32ea0 @attrs={"PORT"=>"1234",
"SERVER"=>"1.2.3.4", "UID"=>"user1", "PWD"=>"password",
"DRIVER"=>"{FreeTDS}"}, @name="Driver1">
This was the driver created by the code (with the modifications):
#<ODBC::Driver:0x18f72cf0 @name="Sequel ODBC Driver130",
@attrs={"DISCONNECTION_PROC"=>"#<Proc:0x0000000018b94020@/opt/ruby-
enterprise/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/database/
misc.rb:43>", "PORT"=>"1234", "ADAPTER"=>"odbc", "UID"=>"user",
"SERVER"=>"1.2.3.4", "DB_TYPE"=>"mssql", "PWD"=>"password",
"DRIVER"=>"{FreeTDS}", "SINGLE_THREADED"=>"false"}>
which is close enough.
The modifications in odbc.rb:
33c33
< drv.attrs[param.to_s.capitalize] = value
---
> drv.attrs[param.to_s.upcase] = value.to_s
The capitalize part is important, the value.to_s is just a dirty hack.
Probably it would be better to
ignore :disconnection_proc, :single_threaded, and the like (since they
were not passed in the connect call).
The connect command for sequel irb used in these tests:
Sequel.connect(:adapter=>'odbc',:driver=>'FreeTDS',:server=>'1.2.3.4',:port=>1234,
:uid=>'user',:pwd=>'password',:db_type=>'mssql').run("SELECT
1")
Of course, there should be an entry in obdcinst.ini named FreeTDS.
Can you update this code to the gem?
Thanks,
Ricardo Ramalho
On Aug 5, 4:25 pm, Jeremy Evans <[email protected]> wrote:
> On Aug 5, 8:06 am, Ricardo Ramalho <[email protected]>
> wrote:
>
>
>
> > Hi. I'm trying to connect to a MSSQL Server using sequel on a linux
> > (Red Hat) machine. Everything is setup properly unixodbc, freeTDS,
> > odbc.ini, odbcinst.ini. If i connect using ODBC DSN:
>
> > Sequel.odbc(:database=>'db-odbc', :user=>'user', :password=>'pwd')
> > ["Select 1"].each {|r| p r}
>
> > t works fine. But i don't want the configuration in odbc.ini files, i
> > need to manage it in the application. If i try to use DSN-less
> > connections
>
> > Sequel.odbc(:driver=>'{FreeTDS}', :servername=>'1.2.3.4', :port=>'1234',
> > :user=>'user', :password=>'pwd')
> > ["Select 1"].each {|r| p r}
>
> > or event without the guards:
>
> > Sequel.odbc(:driver=>'{FreeTDS}', :servername=>'1.2.3.4', :port=>'1234',
> > :user=>'user', :password=>'pwd')
> > ["Select 1"].each {|r| p r}
>
> > it fails with this error:
>
> > Sequel::DatabaseConnectionError: TypeError: can't convert false into
> > String
> > from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/sequel-3.13.0/
> > lib/sequel/adapters/odbc.rb:36:in `drvconnect'
> > from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/sequel-3.13.0/
> > lib/sequel/adapters/odbc.rb:36:in `connect'
> > from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/sequel-3.13.0/
> > lib/sequel/database/misc.rb:44:in `initialize'
> > from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/sequel-3.13.0/
> > lib/sequel/connection_pool.rb:92:in `call'
> > from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/sequel-3.13.0/
> > lib/sequel/connection_pool.rb:92:in `make_new'
> > (...)
>
> > I googled A LOT, and can't find any more information about this. Is
> > there a way to make DSN-less connections using sequel?
> > (http://www.freetds.org/userguide/dsnless.htm)
>
> > I'm using freetds-0.64-6.el5, unixODBC-2.2.11-7.1, ruby-
> > enterprise-1.8.7-4, ruby-odbc (0.99991) and sequel (3.13.0)
>
> I believe Sequel supports (or attempts to support) ODBC DSN-less
> connections, but I've never tried. The relevant method is in the odbc
> adapter:http://github.com/jeremyevans/sequel/blob/master/lib/sequel/adapters/...
>
> If you can get a working connection using ruby-odbc directly, let me
> know and I can probably figure out how to get it working in Sequel.
>
> Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.