Re: tsql knowing which DB to default to

"Tony Baldarelli" <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <00a901cc584c$e04b93f0$a0e2bbd0$@com>
That worked.  Thanks for the idea.

 
Tony

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Raymond R Rankins
Sent: Thursday, August 11, 2011 12:16 PM
To: FreeTDS Development Group
Subject: Re: [freetds] tsql knowing which DB to default to


You can use the -D <databasename> option with tsql to set the default
database when it connects.

-Ray

===============================================
Ray Rankins
[email protected]
(518) 474-1094




From:	"Tony Baldarelli" <[email protected]>
To:	"'FreeTDS Development Group'" <[email protected]>
Date:	08/10/2011 07:33 PM
Subject:	[freetds] tsql knowing which DB to default to
Sent by:	[email protected]



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



_______________________________________________
FreeTDS mailing list
[email protected]
http://lists.ibiblio.org/mailman/listinfo/freetds

IMPORTANT NOTICE: This e-mail and any attachments may contain confidential
or sensitive information which is, or may be, legally privileged or
otherwise protected by law from further disclosure. It is intended only for
the addressee. If you received this in error or from someone who was not
authorized to send it to you, please do not distribute, copy or use it or
any attachments. Please notify the sender immediately by reply e-mail and
delete this from your system. Thank you for your cooperation.
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.