Using ODBC under windows without "default database"

Hi,

I have a need to connect to different databases based on information I
retrieve from a master db. I’m using ruby under Win XP, connecting to a
sqlserver db with odbc.

The odd thing is that I can connect without any problem to a database as
long as I setup the “change the default database to” option in the
creation of the windows odbc data source. But if I don’t specify a
default database - even though I specify the :database when I connect,
it doesn’t find the database.

The code couldn’t be more straightforward (I guess unless it worked!)

foo.establish_connection(
:adapter => “sqlserver”,
:mode => “odbc”,
:dsn => “production”,
:database => “dagoods”,
:username => “theman”,
:password => “secret”
)

I’ve tried different types of dsns and fooled with everything I can
think of - any ideas??

thanks in advance!

Regards
Charlie

Charlie Walden wrote:

Hi,

I have a need to connect to different databases based on information I
retrieve from a master db. I’m using ruby under Win XP, connecting to a
sqlserver db with odbc.

The odd thing is that I can connect without any problem to a database as
long as I setup the “change the default database to” option in the
creation of the windows odbc data source. But if I don’t specify a
default database - even though I specify the :database when I connect,
it doesn’t find the database.

The code couldn’t be more straightforward (I guess unless it worked!)

foo.establish_connection(
:adapter => “sqlserver”,
:mode => “odbc”,
:dsn => “production”,
:database => “dagoods”,
:username => “theman”,
:password => “secret”
)

I’ve tried different types of dsns and fooled with everything I can
think of - any ideas??

thanks in advance!

Regards
Charlie

Duh - solved it and of course it’s obvious, but I’ll leave it here in
case someone else makes the same mistake.

Since no db was specified, you have to send a sql “use” statement over.
so executing the following does the trick:

Foo.connection.select_value(“use databasename”)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs