Skip to Content.
Sympa Menu

freetds - Re: [freetds] tsql knowing which DB to default to

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Raymond R Rankins <rrr03 AT health.state.ny.us>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] tsql knowing which DB to default to
  • Date: Thu, 11 Aug 2011 12:15:30 -0400


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

-Ray

===============================================
Ray Rankins
rrr03 AT health.state.ny.us
(518) 474-1094




From: "Tony Baldarelli" <tbaldarelli AT wmsvision.com>
To: "'FreeTDS Development Group'" <freetds AT lists.ibiblio.org>
Date: 08/10/2011 07:33 PM
Subject: [freetds] tsql knowing which DB to default to
Sent by: freetds-bounces AT lists.ibiblio.org



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
FreeTDS AT lists.ibiblio.org
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.

GIF image




Archive powered by MHonArc 2.6.24.

Top of Page