Import large SQL dump file using sqlcmd - sql-server

In Windows, I am trying to import a large SQL dump file (4.6 GB) into SQL Server 2008. Since it's a large file, I used
sqlcmd -S <SERVER-NAME\INSTANCE> -i C:\<path_to_SQL_file>.sql -o C:\<path_to_output_file_1.txt
However, the command produces the following error:
Error: Syntax error at line 11302 near command '-' in file C:\.sql
In Mac OS X, sed -n '11302p' C:\<path_to_SQL_file>.sql produces
?????$R?}D?XL?)?_K??h?l????????p?^?'?F1璨?¸??ωN?Q???흞????????+/??I?*5jE?1????f?`?nL_?~E?????^ap??Ht?2???g
?2z7$(f???*??????C?????????A?K?хl?B?#??˞K?
q??z?
??I.?
^ ?ݢ?G??cu?Zc?t?'?&L?W??s???W\|x??^_??PǴb???F???m:RY?ES??-D??L?????n??'
3???+?ecKd?vysEkz???wh~;o7?y??\??i
I tried to inspect the file by splitting it using split command but the output is garbled.
Do you think the file is wrongly encoded? How do you feel I should proceed trying to find the error?
The dump file was earlier used by another developer who didn't have any problems with it. Unfortunately, he is on extended vacation for the time being.

Related

BCP Command to Export Query Results to File with Pipe Delimiter

I have a requirement to create a SQL Job that exports a query to a Pipe / Vertical bar delimited file (|) and save it on a network drive in either *.txt or *.csv format. Right now, I am just trying to get this to work inside SSMS, calling the BCP command and exporting the stored procedure in the proper format to the network location, but not able to get it working.
I have been researching this and there are two methods for this.
Use the export data wizard to create a job and schedule that to run. But this method, if we need to make changes, I believe we cannot change the SSIS package that is created so we lose flexibility
Use the BCP command to export the file.
I greatly prefer to use option #2, the BCP command, but I am having problems. I just cannot seem to get the syntax correct and hoping someone could show me what I am missing:
This is my command:
Exec master..xp_cmdshell 'bcp EXEC [dbo].[usp_Report_1123] ''7786'' -t| out \\networkDrive\Reports\REPORT_1123\report1123.csv -T'
But I get the following messages:
output
'out' is not recognized as an internal or external command,
operable program or batch file.
NULL
The stored procedure does work and returns data. The network path, if I enter it into my computer, finds the path. But I am not sure what I am missing and hoping someone could help.

I generate excel sheet with sql query but it generates only in 93 version how can i make it to 2013 version?

exec master..xp_cmdshell 'bcp " Select 'column' union all Select "
cast(column As nvarchar(max))from [NEWDATABASE].[dbo].[TempPower] WHERE BarCode = 'batman'"queryout D:\TempPower.xls -o "D:\querycommanddetails.txt" -T -c -C RAW'"
bcp does not, from the documentation I can find, export to any Excel binary format. What you're doing is producing a delimited text file and giving it an Excel extension. But file extensions don't dictate how the data is stored/represented in the file; they're just a hint to tell Windows what application to open them in and the application a hint about how to process it.
If you open the file in a text editor, you'll see the raw data in plain text there. Excel may even give you a warning when you attempt to open a delimited text file that has the xls extension because it's not getting what it expected.
If you need to output directly to a xslx file, you'll need to produce it through another method.

Sqlcmd Error "The filename, directory name, or volume label syntax is incorrect"

I create a bat file for the first time, and have the following issue: my command is running just fine when I type it directly into the command prompt, but it's not running through the bat file I created. The script is:
#echo off
sqlcmd -S DESKTOP-55JKCD5\SQLEXPRESS -i “C:\Users\Didi\Documents\SQL\test.sql” -o “C:\Users\Didi\Documents\SQL\output.csv” -s”,”
I get the following message from cmd:
Sqlcmd: Error: Error occurred while opening or operating on file ôC:\Users\Didi\Documents\SQL\test.sqlö (Reason: The filename, directory name, or volume label syntax is incorrect).
I can't understand what's wrong, provided that I don't have any issues when typing directly in cmd.
I'm begging for your advice, guys! Bat files are totally new for me, apologies is asking a stupid question.
Don't use "smart quotes"! Use " - in a proper editor, not a word-processor.
If you are running this exe from Azure Dev Ops you can also get this issue if there is a new line in the definition of the step in the Release or Pipeline. The step is multiline so it is difficult to spot. It's the difference between:
ServerRoleMembership;ServerRoles;RoleMembership;Permissions" /v:Environment=$(Environment) /Diagnostics:true
/p:ScriptDatabaseOptions=false
and
ServerRoleMembership;ServerRoles;RoleMembership;Permissions" /v:Environment=$(Environment) /Diagnostics:true /p:ScriptDatabaseOptions=false
Both look same in Dev Ops, it's only when you copy them out to notepad you will see the new line

Running a batch file on Kid3 ID3 MP3 tagger

I finally gave up after 120 hours of not finding a .NET or javascript/jquery plugin that can read and write to a COMPRESSED custom user frame (TXXX) in ID3v2 MP3 audio file.
UltraID3Lib: cannot read or write COMPRESSED Frames (last updated 2009, author Mitchell S. Honnert fell off face of the earth).
ID3Lib-sharp: cannot read or write COMPRESSED Frames (last updated 2012)
JavaScript-ID3-Reader: can return bytes but it's mostly the wrong bytes. Cannot write anything.
I cannot use the multitudes of Node.js or PHP scripts for my project so they are out of the question.
The only code I found that can read and write compress frames is Kid3.
http://sourceforge.net/projects/kid3/
However, it is written in C (I don't know that) and uses third party frameworks since it was not built in windows. The Command program required 13MB of support dlls, QMs, and whatevers.
I have no choice at his point but to try and use it's separate command program kid3-cli.exe
So here's my question:
Here is the way to read a TXXX frame using the program at the command prompt.
"71F3-15-FOO58A77" is the name of the TXXX frame and the "2" gets the text value it holds:
cd "C:\mp3folder"
select "test.mp3"
get "71F3-15-FOO58A77" "2"
export "clipboard" "CSV unquoted" "2"
QUESTION: HOW DO I use a Batch file to run these commands?
According to kid3 documents. It shows using -c as grouped commands. Windows cmd (or the program) on windows does know what -c is.
Example: I double click the batch file and it should:
start the program
sent the program (not cmd) the above 4 lines
each must be executed separately.
Sounds simple, but I can't get it to even execute one of the programs code after starting.
Any ideas? and and can someone write a ID3 tag program that can read and write COMPRESSED TXXX tags without using node.js, PHP or a server in Windows.
I will buy them a beer because I'm really a (cheap) designer by trade and a pert-time programmer only when I have too.
Here is a zip file of a COMPRESSED TXXX Frame in test.mp3 to test:
[http://robbiestewart.ca/test.zip][1]
Download Kid3 and use its windows GUI (kid3.exe) to view the custom user frame (TXXX).
Run the included kid3-cli.exe to do the same at the command prompt.
Try to do the same in a batch file.
According to the help file, you should be able to use the command
kid3-cli -c 'cd "C:\mp3folder"' -c 'select "test.mp3"' -c 'get "71F3-15-F0058A77" "2"' -c 'export "clipboard" "CSV unquoted" "2"'
I ran it on the file you provided and seven tabs followed by 0:00.00 were put on my clipboard, but the value of the TXXX field indicated by the GUI was output to my command prompt.

Mysql import error from bash script

i have a big database dump (290mb). When i use import from cli everything is ok!
mysql -u root -piddqd whitestore_com < whitestore_com.sql
When i use the same command from bash script like:
./build.sh
Here is what i get:
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (\!) Execute a system shell command.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax
to use near 'mysql Ver 14.14 Distrib 5.1.66, for debian-linux-gnu (x86_64)
using readline 6.' at line 1
I dont know why I get this error, there is no such string as "mysql Ver 14.14 Distrib 5.1.66, for debian-linux-gnu (x86_64) in dump file
using readline 6."
Try opening up the whitestore_com.sql in a text editor and check the first couple of lines.
It looks like there's some text at the start of the .sql file that should be commented out.
It's opening up the mysql connection ok, but then the commands it's getting from whitestore_com.sql aren't valid SQL statements.

Resources