sqlcmd

Free SQL Server development tools

I usually use Management Studio and SQLCMD to work with SQL Server. For the most part, they work for me. I'm just kind of curious what else is out there. I just want to find out if there are any needs I have that are unfulfilled. So what are some helpful SQL Server tools? There's no particular functionality I'm looking to replace or...

Connect to SQL Server from cygwin window times out, from DOS prompt works

The title says it all. I can connect to my SQL Server database via sqlcmd from a DOS command window, but not from a Cygwin window. From DOS: F:\Cygnus>sqlcmd -Q "select 'a test'" -S .\SQLEXPRESS a test (1 rows affected) F:\Cygnus> ==================================================== From Cygwin: $ sqlcmd -Q "select 'a...

SQL Server 2005 - get an XML field into a file; some xml fields into their own files

I got a row structure looks like ID bigint, ScanRept XML I want to wind up with a file named 4.xml containing just the xml from the ScanRept column where the ID number is 4. I don't want to do it interactively (by going into Manager Studio, finding the row, right-clicking the field and doing Save AS) - that's what I'll do if I can't fi...

Batch script for re-creating database from source control

Hi Everyone, As far as I understand, if I want to get my database under source control then I need to be checking in change scripts for each change and then running them from some revision to get the correct DB. I am trying to make a batch file that will be checked in too, that allows other developers on the team to re-build the DB loc...

Can't connect to SQL Server Express using sqlcmd.exe

Hi All, Env.: Vista SP1, SQL Server Express 2005 I'm able to connect to my localhost SQL Server using SQL Server Management Studio, using Windows authentication and, to the best of my knowledge, all default parameters, including network protocol. Now I try to connect using sqlcmd.exe to no avail: C:\Program Files\Microsoft SQL Server...

Getting sqlcmd output into a GridView

I am designing an ASP.NET website that will run sqlcmd, get some output and put this into a grid on screen. I was wondering if there is a method for reading the results of a query from sqlcmd into some kind of format that I can work with, XML, DataSet etc. Is there a friendly switch in sqlcmd that will output it in a nice format or wil...

DB Pro (data dude) and Wix3 SqlExtension

I'm attempting to use Wix to create a database during install. I have my database setup with the Db Pro Visual Studio SKU (Data Dude as it's sometimes referred). However, the output seems to be only consumable by sqlcmd.exe since it uses specific syntax in it (variable references like :setenv and $(FOO)). I'm trying to use the wix sqlex...

How to export data as CSV format from SQL Server using sqlcmd?

I can quite easily dump data into a text file such as: sqlcmd -S myServer -d myDB -E -Q "select col1, col2, col3 from SomeTable" -o "MyData.txt" However, I have looked at the help files for sqlcmd but have not seen an option specifically for CSV. Is there a way to dump data from a table into a CSV text file using sqlcmd? ...

how to avoid sqlcmd blank line between Resultsets?

hello, refering my last question on extracting SQL stored procedures into .sql files (see here) I have another question: how to avoid or delete the sqlcmd blank line between Resultsets? Reason (see MSDN) When multiple results are returned, sqlcmd prints a blank line between each result set in a batch. This means that stored procedures...

How can I run sqlcmd.exe from an ASP page? (Free hat)

As part of our database revision control (and auto-installation) procedures we need to be able run sqlcmd.exe on various .sql files from within an ASP page. The code I'm using to do this is: Dim cmd : cmd = "sqlcmd -S " & DATABASE_SERVER & " -U " & DATABASE_UID & " -P " & DATABASE_PWD & " -d " & DATABASE_NAME & " -i """ & scriptPath & "...

Dealing with SQLCMD :r in a post-deployment script

We use a Visual Studio Database Project for the source control of the schema of our database. We also want to script certain data (configuration values etc.) from the database, so we use a custom command line utility for dumping data into insert scripts. One file represents one table's scripted data. There is a certain SQL script, calle...

Powershell Sqlcmd popup in c#

I have a PSHost object executing a Powershell script myscript.ps1 and that .ps1 script is executing sqlcmd.exe to get what it needs done. Is there a way to keep it from popping up empty sqlcmd dos prompts (as it seems to do)? ...

How to export SQL Server 2005 query to CSV

I want to export some SQL Server 2005 data to CSV format (comma-separated with quotes). I can think of a lot of complicated ways to do it, but I want to do it the right way. I've looked at bcp, but I can't figure out how to put the quotes around the fields (except concatenating them to the field values, which is ugly). I guess I could do...

SQLCMD, command-line variables and script :setvar

When running SQLCMD.exe and providing command-line arguments for scripting variables, I expect that the values provided on the command-line will override those defined in the SQL script file. e.g. Given the following SQL Script: :setvar XXX "SQL script" print '$(XXX)' And the command line: sqlcmd.exe -S <Server> -d <Database> -E -b...

How to execute 3GB SQL file (Micrsoft SQL Server)?

I have a big SQL file that does not fit into memory and that needs to be executed against Microsoft SQL Server 2008. It seems that the sqlcmd.exe tool always loads it into memory first which is impossible in this case. Any ideas? unfortunately, i cannot split the script because it is generated by Redgates excellent SQL Data Compare. the...

Powershell SQLCMD

We were experiencing problems with Powershell and SQLCMD, when there was sapces in the -v parameter variable powershell wouldn't run the command. e.g. sqlcmd ... -v VAR="Some space" Has anyone experienced this before or know how to fix the problem? Thanks, B ...

Display DataType and Size of Column from SQL Server Query Results at Runtime

Is there a way to run a query and then have SQL Server management studio or sqlcmd or something simply display the datatype and size of each column as it was received. Seems like this information must be present for the transmission of the data to occur between the server and the client. It would be very helpful to me if it could be dis...

Trying to restore a database from a large .sql file using sqlcmd - error

I am trying to restore database data using the following command from a large .sql file "Type myfile.sql | sqlsmd –S server –U username –P password" I get the following error: Sqlcmd: Error: Scripting error. I am unable to open the file, there is not enough memory. ...

SQLCMD.EXE generates ugly report. How to format it?

I did batch to run SQL query like use [AxDWH_Central_Reporting] GO EXEC sp_spaceused @updateusage = N'TRUE' GO It displays 2 tables and generates some ugly report with some kind of 'P' unneeded letters... See below Changed database context to 'AxDWH_Central_Reporting'. database_name ...

How do we tell sqlcmd to continue "on error" with next batch?

Any ideas on how to accomplish this? USE [db_name] BEGIN TRANSACTION ...TONS OF INSERTS COMMIT; RAISERROR (..) WITH NOWAIT; //If error continue with next batch BEGIN TRANSACTION ...TONS OF INSERTS COMMIT; RAISERROR (..) WITH NOWAIT; ... ...