more to come...
Accessing a DatabaseAccessing Microsoft SQL Server from a non-Microsoft platform requires the FreeTDS library and a client that uses it such as SQSH.
FreeTDSI've sucessfully installed FreeTDS on Linux, FreeBSD, NetBSD, OpenBSD, SCO OpenServer and Solaris. I had to compile from source on Linux, SCO OpenServer and Solaris. FreeTDS is available from the FreeTDS home page. It compiles cleanly on all platforms. When compiling from source, I usually give the configure script the --prefix=/usr/local/freetds parameter so that FreeTDS will be installed entirely under /usr/local/freetds and then add /usr/local/freetds/lib to my LD_LIBRARY_PATH environment variable.
FreeBSD, OpenBSD and NetBSD come with FreeTDS and give you the option of installing it when you install the rest of the system. If you want or need to install it afterward, follow the instructions below.
FreeBSDIf you have an internet connection, run pkg_add -r freetds. When the command completes, FreeTDS will be installed. You can also install FreeTDS from the Ports CD(s) that came with your distribution using /stand/sysinstall.
OpenBSDThe freetds package is available from ftp.openbsd.org or on CD's that came with your distribution. You can install it using pkg_add.
NetBSDThe freetds package is available from ftp.netbsd.org or on CD's that came with your distribution. You can install them using pkg_add.
SQSHI've sucessfully installed SQSH on Linux, FreeBSD, NetBSD, OpenBSD, SCO OpenServer and Solaris. On all platforms, I've had to compile it from source. SQSH is available from the SQSH home page. It compiles cleanly on all platforms.
SQSH can be compiled against FreeTDS libraries or Sybase native libraries. To use SQSH with Microsoft SQL Server, it must be compiled against FreeTDS. The SQSH configure script uses the SYBASE environment variable to decide where to look for the necessary include files and libraries. You must set this variable before attempting to compile SQSH. For example, if you installed FreeTDS in /usr/local/freetds, you can set the environment variable as follows.
For Bourne shells:
SYBASE=/usr/local/freetds export SYBASE
For C-shells:
setenv SYBASE /usr/local/freetds
I usually give the configure script the --prefix=/usr/local/sqsh parameter so that SQSH will be installed entirely under /usr/local/sqsh and then add /usr/local/sqsh/bin to my PATH environment variable.
Once you have FreeTDS and SQSH installed, you can access the database using SQSH. Note that you will need to have the SYBASE environment variable set when running SQSH.
SQSH requires a username, server and database name to access a database. The server parameter does not refer to the hostname of the machine you want to connect to, but rather to an entry in the $SYBASE/interfaces file. Below is a sample entry for a server named remotehost which refers to an instance of Microsoft SQL Server running on testhost.testdomain.com, on port 1433, accessible over tcp on ethernet.
remotehost master tcp ether testhost.testdomain.com 1433 query tcp ether testhost.testdomain.com 1433
Similar entries can be made to access servers running on other hosts.
To access the database testdb on the server localhost as the user testuser, run the following command.
sqsh -U testuser -S localhost -D testdb
more to come...
Accessing a Database With SQL RelayAccessing Microsoft SQL Server from SQL Relay requires an instance entry in your sqlrelay.conf file for the database that you want to access. Here is an example sqlrelay.conf which defines an SQL Relay instance called freetdstest. This instance connects to the testdb database on the server remotehost as the user testuser with password testpassword.
<?xml version="1.0"?> <!DOCTYPE instances SYSTEM "sqlrelay.dtd"> <instances> <instance id="freetdstest" port="9000" socket="/tmp/freetdstest.socket" dbase="freetds" connections="3" maxconnections="5" maxqueuelength="0" growby="1" ttl="60" endofsession="commit" sessiontimeout="600" runasuser="nobody" runasgroup="nobody" cursors="5" authtier="listener" handoff="pass"> <users> <user user="freetdstest" password="freetdstest"/> </users> <connections> <connection connectionid="freetdstest" string="server=remotehost;db=testdb;user=testuser;password=testpassword" metric="1"/> </connections> </instance> </instances>
Now you can start up this instance with the following command.
sqlr-start -id freetdstest
To connect to the instance and run queries, use the following command.
sqlrsh -id freetdstest
The following command shuts down the SQL Relay instance.
sqlr-stop freetdstest