Solved

SQL server 2005 command line client

Posted on 2011-03-12
11
590 Views
Last Modified: 2012-05-11
Is there any client program available to connect to SQL server 2005 or SQL server 2008 via the server name and login credentials and then run sql query to dump the output to a .csv file?

I do the same way with mysql server. I have mysql client and I connect to the database and query via an automated script. Can I do the same for SQL server 2005 database?
0
Comment
Question by:toooki
  • 6
  • 3
  • 2
11 Comments
 
LVL 11

Accepted Solution

by:
JoeNuvo earned 475 total points
ID: 35119860
on windows,  sqlcmd can do the job

http://www.sqlservercurry.com/2010/01/using-sqlcmd-to-export-sql-server-data.html

but as your question put under Zone Unix as well, then maybe you need to try this link, too

http://linux.softpedia.com/get/Database/Database-APIs/sqlcmd-42911.shtml
0
 

Author Comment

by:toooki
ID: 35119958
Thank you.
It seems I need Python installed in order to use sqlcmd .
0
 
LVL 28

Expert Comment

by:Ryan McCauley
ID: 35125289
You don't need Python to use SQLCMD - it's installed as part of the SQL Server Client Connectivity option, and you can use it without any additional installs. The first link JoeNuvo provides is exactly what you're looking for, if I understand your question correctly.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:toooki
ID: 35135512
Yes that is right. Thank you.
I just worked on my laptop that has SQL Server 2005 express installed.
Is there any way to make it work on a Linux server that does not have SQL Server 2005 installed?
0
 
LVL 28

Expert Comment

by:Ryan McCauley
ID: 35138958
Are you talking about a Linux version of SQLCMD that connects to SQL Server databases, or one that connects to MySQL databases? I don't believe a SQL Server version of this tool exists for Linux, but I'd be surprised if a version for MySQL wasn't installed as part of the client tools.
0
 

Author Comment

by:toooki
ID: 35144437
Thanks.Yes you are right..
I was asking about a Linux version of SQLCMD that connects to Microsoft SQL Server database. I understand that may not exist. So I cannot run SQLCMD on a Linux server.

Yes I used MySQL on Linux server and that works..

But was wondering if I could connect to another Microsoft SQL Server from this Linux server...looks like I cannot.
0
 
LVL 11

Expert Comment

by:JoeNuvo
ID: 35144500
since I don't have linux myself, I can't try the sqlcmd from URL I given to you.
if you think it worth your time, you should give it a try.
0
 

Author Comment

by:toooki
ID: 35144821
Yes, I looked at the documentation for the Linux sqlcmd tool. But the README file says:
sqlcmd requires the following:

Python 2.5 or better
The Grizzled API (automatically installed if you use easy_install to install sqlcmd)
The enum package (automatically installed if you use easy_install)
Appropriate Python DB API drivers for the database(s) you want to use. (See Database Types, below.)
Windows only: You'll also want the ipython pyreadline package, available via easy_install or from http://ipython.scipy.org/dist 


I do not have permission to install Python or so on the Linux server.

0
 

Author Comment

by:toooki
ID: 35144838
I am trying to run the sqlcmd on a Windows server. And the sqlcmd is downloading the dump file. The problem is that the file gets padded by huge amount of blank spaces.

My sqlcmd is:
sqlcmd -U myUser -P myPwd -S myServer.myco.com -d myDB -Q "select LTRIM(RTRIM(F1)), LTRIM(RTRIM(F2)) from dbo.myTab" -o "D:\myFile.txt" -s","

Problem is not at the source table. I do not know how to get rid of these blank spaces. The sqlldr command cannot detect the file content.

 dump.txt
0
 
LVL 11

Expert Comment

by:JoeNuvo
ID: 35145093
to run on Windows with sql installed, maybe using BCP is better way.

try following command

BCP "select LTRIM(RTRIM(F1)), LTRIM(RTRIM(F2)) from myDB.dbo.myTab" queryout D:\myFile.txt -c -t\t -r\n -U username -P password -S myServer.myco.com

note
1) output will have tab as delimit
2) I don't sure about BCP tool for linux, but from what I looking for, it also required Python which is not able to do in your situation.
0
 

Author Comment

by:toooki
ID: 35162326
JoeNuvo, thank you for the help but the BCP command did not work. Got syntax error/etc. So I am ok with the sqlcmd and I will trim the values before loading to sqlldr. Seems it is working.
Thanks everyone for help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question