What are some ways to access Microsoft SQL Server from Linux?

We have a Windows machine running SQL Server 2005, and we need to be able to run some database queries on Linux from a Linux window. What are some of the recommended ways to do this? Ideally, we need a command line utility like sqlcmd for Windows.

+43
sql-server
Sep 29 '08 at 16:09
source share
10 answers

FreeTDS + unixODBC or iODBC

Install FreeTDS first, then configure one of the two ODBC engines to use FreeTDS as your ODBC driver. Then use the command line interface for the ODBC engine.

unixODBC has isql, iODBC has iodbctest

You can also use your favorite programming language (I have successfully used Perl, C, Python and Ruby to connect to MSSQL)

I personally use FreeTDS + iODBC:

$more /etc/freetds/freetds.conf [10.0.1.251] host = 10.0.1.251 port = 1433 tds version = 8.0 $ more /etc/odbc.ini [ACCT] Driver = /usr/local/freetds/lib/libtdsodbc.so Description = ODBC to SQLServer via FreeTDS Trace = No Servername = 10.0.1.251 Database = accounts_ver8 
+31
Sep 29 '08 at 16:14
source share

sqsh ( http://www.sqsh.org/ ) + freetds ( http://www.freetds.org )

sqsh was primarily a replacement for isql for Sybase SQL Server (now ASE), but it is great for connecting to SQL Server (when using freetds).

To compile, just specify $ SYBASE to install freetds, and it should work from there. I use it on my Mac all day.

The best part of sqsh is advanced functions such as dead simple server binding (no need to install linked servers in SQL Server), flow control and loop (no more string concatenation and dynamic SQL execution), as well as an invisible copy / load mass.

Anyone using any other command line tool is just crazy! :)

+9
Sep 29 '08 at 21:55
source share

sql-cli is a command line interface with a nodejs-based platform for sql server. You can install it through npm https://www.npmjs.org/package/sql-cli

It can connect to both an internal and sql-azure instance.

+9
May 12 '14 at 4:37
source share

pymssql is a Python DB-API module based on FreeTDS. It worked for me. Create some helper functions if you need and use them from the Python shell.

+6
Sep 29 '08 at 16:32
source share

Mono contains an ADO.NET provider who should do this for you. I donโ€™t know if there is a command line utility for it, but you can definitely complete some C # to execute queries if that doesnโ€™t happen.

Take a look at http://www.mono-project.com/TDS_Providers and http://www.mono-project.com/SQLClient

+5
Sep 29 '08 at 16:16
source share

Since November 2011, Microsoft has provided its own ODBC driver for SQL Server for Linux for Red Hat Enterprise Linux (RHEL) and SUSE Linux Enterprise Server (SLES).

It also includes sqlcmd for Linux.

+4
Sep 20 '14 at 12:41
source share
+3
Sep 29 '08 at 22:02
source share

You do not say what you want to do with the resulting data, but if these were general requests for development / maintenance, I would have thought that Remote Desktop on a Windows server, and then using real SQL Server tools, they would always be a more productive option for any hacked solution on Linux itself.

+2
Sep 29 '08 at 16:21
source share

For PHP, there is an abstraction of lib. Not sure what your client block will support, but if its Linux, of course, should support the creation of the PHP query interface with this: http://adodb.sourceforge.net/ Hope this helps.

+2
Sep 29 '08 at 16:35
source share

I was not at ease with the freetds solution, this is why I coded the class (command history, autocomplete tables and fields, etc.).

http://www.phpclasses.org/package/8168-PHP-Use-ncurses-to-get-key-inputs-and-write-shell-text.html

0
Oct 22 '13 at 15:58
source share



All Articles