Does anyone have any experience getting ODBC to work? I could really use
some help here.
I''m having trouble accessing a db2 database via odbc using rails.
It''s an
external database, that I import data from. I have placed the connection
code in my model :
unless connected?
establish_connection(
:adapter => "odbc",
:dsn => "<dsn name>",
:username => "<name>",
:password => "<passwd>"
)
end
When I call this via the console, I get a " unknown adapter" error.
I''ve
checked and an odbc file is included.
--
Best Regards,
-Larry
"Work, work, work...there is no satisfactory alternative."
--- E.Taft Benson
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060310/a8c15dd2/attachment.html
Actually, I don''t think anyone has written a generic odbc adapter for rails. I could be wrong, but I don''t see one in trunk. There IS, however, a db2 adapter. You can use :adapter => ''db2'' to connect to your database. According to api.rubyonrails.com the db2 adapter takes the following options: :username ? Defaults to nothing :password ? Defaults to nothing :database ? The name of the database. No default, must be provided. Of course, I''ve never used db2 myself, so I''m sure someone else on the list can offer more insight. -Derrick Spell On Mar 10, 2006, at 10:13 AM, Larry Kelly wrote:> Does anyone have any experience getting ODBC to work? I could > really use some help here. > > I''m having trouble accessing a db2 database via odbc using rails. > It''s an external database, that I import data from. I have placed > the connection code in my model : > > unless connected? > establish_connection( > :adapter => "odbc", > :dsn => "<dsn name>", > :username => "<name>", > :password => "<passwd>" > ) > end > > When I call this via the console, I get a " unknown adapter" > error. I''ve checked and an odbc file is included. > > > -- > Best Regards, > -Larry > "Work, work, work...there is no satisfactory alternative." > --- E.Taft Benson > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060310/9b8cbc6c/attachment-0001.html
There is currently no ODBC adapter for Rails. there is a db2 adapter, but i
am not familiar with how weil it works.
I have a similar situation. I have to access data on an AS/400. only way
is via odbc. I use ruby dbi and ruby odbc to retrieve the information then
create AR objects from the returned data. Seems to work well for my
situation since I am only retrieving data or calling stored procedures on
the AS/400.
I created a module in my lib dir and I require it where needed.
for example:
lib/AS400.rb
module AS400
def AS400.find_something(something)
begin
dbh = DBI::connect("DBI:ODBC:" + LIB, UID, PWD)
row = dbh.select_one("select * from table where something
''something''")
rescue DBI::DatabaseError => e
raise e.errstr
ensure
dbh.disconnect unless dbh.nil?
end
row.nil? ? nil : row[0]
end
end
then in the controllers where I need to use it, I just add
require_dependency ''AS400''
then in the action where you want to use it:
def some_action
begin
@foo = Foo.new
something = AS400.find_something(@params[:something])
@foo.name = something unless something.nil?
rescue Exception => error
flash.now[''error''] = "AS/400 Error: " + error
end
end
hope this helps.
On 3/10/06, Larry Kelly <ldk2005@gmail.com> wrote:>
> Does anyone have any experience getting ODBC to work? I could really use
> some help here.
>
> I''m having trouble accessing a db2 database via odbc using rails.
It''s an
> external database, that I import data from. I have placed the connection
> code in my model :
>
> unless connected?
> establish_connection(
> :adapter => "odbc",
> :dsn => "<dsn name>",
> :username => "<name>",
> :password => "<passwd>"
> )
> end
>
> When I call this via the console, I get a " unknown adapter"
error. I''ve
> checked and an odbc file is included.
>
>
> --
> Best Regards,
> -Larry
> "Work, work, work...there is no satisfactory alternative."
> --- E.Taft Benson
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060310/200e41cf/attachment-0001.html
>> Does anyone have any experience getting ODBC to work? I could really use >> some help here. >> >> I''m having trouble accessing a db2 database via odbc using rails. > There is currently no ODBC adapter for Rails.For access to MSSQL (from rails on Linux), I did use: * Installed and configured ODBC on the Linux box to connect to MS SQL * Used an adapted ActiveRecord connection adapter: # odbc_adapter.rb -- ActiveRecord adapter for ODBC # # adapted from: # sqlserver_adapter.rb -- ActiveRecord adapter for Microsoft # SQL Server # # Author: Joey Gibson <joey@joeygibson.com> # Date: 10/14/2004 # # Modifications: DeLynn Berry <delynnb@megastarfinancial.com> # Date: 3/22/2005 It worked, but not perfectly; I definitely prefer to use a native adapter.
Thanks for the replies. everyone. Chris, This looks close to what need. I''ll try it out this afternoon. Without looking at the docs, can I assume that the ''LIB'' in the connection setup refers to the DSN that I will be using? Thanks, again. -Larry On 3/10/06, Chris Hall <christopher.k.hall@gmail.com> wrote:> > There is currently no ODBC adapter for Rails. there is a db2 adapter, but > i am not familiar with how weil it works. > > I have a similar situation. I have to access data on an AS/400. only way > is via odbc. I use ruby dbi and ruby odbc to retrieve the information then > create AR objects from the returned data. Seems to work well for my > situation since I am only retrieving data or calling stored procedures on > the AS/400. > > I created a module in my lib dir and I require it where needed. > > for example: > > lib/AS400.rb > > module AS400 > def AS400.find_something(something) > begin > dbh = DBI::connect("DBI:ODBC:" + LIB, UID, PWD) > row = dbh.select_one("select * from table where something > ''something''") > rescue DBI::DatabaseError => e > raise e.errstr > ensure > dbh.disconnect unless dbh.nil? > end > row.nil? ? nil : row[0] > end > end > > then in the controllers where I need to use it, I just add > > require_dependency ''AS400'' > > then in the action where you want to use it: > > def some_action > begin > @foo = Foo.new > something = AS400.find_something(@params[:something]) > @foo.name = something unless something.nil? > rescue Exception => error > flash.now [''error''] = "AS/400 Error: " + error > end > end > > hope this helps. > > > On 3/10/06, Larry Kelly < ldk2005@gmail.com> wrote: > > > Does anyone have any experience getting ODBC to work? I could really > use some help here. > > I''m having trouble accessing a db2 database via odbc using rails. It''s an > external database, that I import data from. I have placed the connection > code in my model : > > unless connected? > establish_connection( > :adapter => "odbc", > :dsn => "<dsn name>", > :username => "<name>", > :password => "<passwd>" > ) > end > > When I call this via the console, I get a " unknown adapter" error. I''ve > checked and an odbc file is included. > > > -- > Best Regards, > -Larry > "Work, work, work...there is no satisfactory alternative." > --- E.Taft Benson > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060310/9b24f9c1/attachment.html
Did this work well enough for production? When I have time, I intend to explore Rails on Linux. But, the Linux box would have to be able to communicate with the Windows LAN. On 3/10/06, brabuhr@gmail.com <brabuhr@gmail.com> wrote:> > >> Does anyone have any experience getting ODBC to work? I could really > use > >> some help here. > >> > >> I''m having trouble accessing a db2 database via odbc using rails. > > There is currently no ODBC adapter for Rails.For access to MSSQL (from rails on Linux), I did use:> * Installed and configured ODBC on the Linux box to connect to MS SQL > * Used an adapted ActiveRecord connection adapter: > # odbc_adapter.rb -- ActiveRecord adapter for ODBC > # > # adapted from: > # sqlserver_adapter.rb -- ActiveRecord adapter for Microsoft > # SQL Server > # > # Author: Joey Gibson <joey@joeygibson.com> > # Date: 10/14/2004 > # > # Modifications: DeLynn Berry <delynnb@megastarfinancial.com> > # Date: 3/22/2005 > > It worked, but not perfectly; I definitely prefer to use a native adapter. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060310/dbab836e/attachment.html
>> For access to MSSQL (from rails on Linux), I did use: >> >> * Installed and configured ODBC on the Linux box to connect to MS SQL >> * Used an adapted ActiveRecord connection adapter: >> >> It worked, but not perfectly; I definitely prefer to use a native adapter.> Did this work well enough for production?It worked well enough for my purposes at the time. But, it was an app for a very small user community (me + a few others), so I don''t have any idea how it would react to a large load. The two issues I had: * Scaffold Generation * Pagination Helper
Larry, yes, its the name of the datasource in odbc.ini LIB/UID/PWD are just constants i set in config/environments/* since i have different datasources for dev/prod/test. On 3/10/06, Larry Kelly <larry@tellinkltd.com> wrote:> > Thanks for the replies. everyone. > > Chris, This looks close to what need. I''ll try it out this afternoon. > Without looking at the docs, can I assume that the ''LIB'' in the connection > setup refers to the DSN that I will be using? > > Thanks, again. > -Larry > > > On 3/10/06, Chris Hall <christopher.k.hall@gmail.com> wrote: > > > > There is currently no ODBC adapter for Rails. there is a db2 adapter, > > but i am not familiar with how weil it works. > > > > I have a similar situation. I have to access data on an AS/400. only > > way is via odbc. I use ruby dbi and ruby odbc to retrieve the information > > then create AR objects from the returned data. Seems to work well for my > > situation since I am only retrieving data or calling stored procedures on > > the AS/400. > > > > I created a module in my lib dir and I require it where needed. > > > > for example: > > > > lib/AS400.rb > > > > module AS400 > > def AS400.find_something(something) > > begin > > dbh = DBI::connect("DBI:ODBC:" + LIB, UID, PWD) > > row = dbh.select_one("select * from table where something > > ''something''") > > rescue DBI::DatabaseError => e > > raise e.errstr > > ensure > > dbh.disconnect unless dbh.nil? > > end > > row.nil? ? nil : row[0] > > end > > end > > > > then in the controllers where I need to use it, I just add > > > > require_dependency ''AS400'' > > > > then in the action where you want to use it: > > > > def some_action > > begin > > @foo = Foo.new > > something = AS400.find_something(@params[:something]) > > @foo.name = something unless something.nil? > > rescue Exception => error > > flash.now [''error''] = "AS/400 Error: " + error > > end > > end > > > > hope this helps. > > > > > > On 3/10/06, Larry Kelly < ldk2005@gmail.com> wrote: > > > > > Does anyone have any experience getting ODBC to work? I could really > > use some help here. > > > > I''m having trouble accessing a db2 database via odbc using rails. It''s > > an external database, that I import data from. I have placed the connection > > code in my model : > > > > unless connected? > > establish_connection( > > :adapter => "odbc", > > :dsn => "<dsn name>", > > :username => "<name>", > > :password => "<passwd>" > > ) > > end > > > > When I call this via the console, I get a " unknown adapter" error. > > I''ve checked and an odbc file is included. > > > > > > -- > > Best Regards, > > -Larry > > "Work, work, work...there is no satisfactory alternative." > > --- E.Taft Benson > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > -- > Best Regards, > -Larry > "Work, work, work...there is no satisfactory alternative." > --- E.Taft Benson > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060311/bdcae981/attachment.html