tsql knowing which DB to default to

"Tony Baldarelli" <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <004f01cc57b4$f15f82c0$d41e8840$@com>
Hello,

                For my production server, it just so happens that the
database I use is the default database.  As such, I don't need to use the
following to connect to the correct database inside tsql:

                use <database>

                go

But now we have 2 other databases that just happen to be on the same server.
This requires me to use the "use <database>" pattern to connect to the
correct database.  I thought this setup would get around that requirement,
but it does not:

                [Wms_Stage]

                    host = PBMVMWMSSQLDEV

                    port = 1433

                    tds version = 8.0

                    database=WMS_STAGE

I actually think "database" is not supported as I don't see it in the
documentation online.  So either that changed, or someone added it and then
never got rid of it since it does not seem to cause a problem.  I want to
make my application ( including SQL scripts ) as blind as possible to the
database, but I cannot if I have to use the "use <database>" pattern for 2
databases, but not the production one.  Is there a way to tell tsql to use a
particular database so I don't have to?  Note that since "tsql" is run from
a special shell script ( called "sql" ), a perfectly valid option would be
to have a command line option to tsql that tells tsql to use a particular
database.  Also, an environmental variable would also work, for this same
reason.  Thanks.  I could not see an obvious way to do it in the
documentation.

 

In case you are wondering, I commonly run a command like this: sql <
report.sql.  Since "sql" is defined differently for each database (
actually, each Linux user ), I just want to be able to "run" the same sql
script against all 3 databases without any changes at all.  Thus my
questions above.  Here is an example of the "sql" script using the above
freetds.conf setup:

                [wmsStage]> more sql

                tsql -S Wms_Stage -U <user name removed for security> -P
<Password removed for security>

                echo

                [wmsStage]>

 

Tony Baldarelli
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.