Executing large script file (1.7GB) on Microsoft SQL Server using SQLCMD - sql-server

I have a generated script file with 1.7 GB size, I'm trying to run this script using the following sqlcmd
sqlcmd -m1 -S 192.168.100.10\SQLHQ -U sa -P 123456 -i "E:/VMS2008R2.sql"
When I run this line in CMD as administrator, the command take some time and give me no error, the database schema generated to database but without data and without any success or finished message!
UPDATE
When I run the command without -m1 I got the following exception:
TCP Provider: An existing connection was forcibly closed by the remote host.
Communication link failure

Related

SQL Server Express backup script

I was able to perform backup for my SQL Server Express using this command at the command prompt:
SQLCMD -E -S testing\SQLEXPRESS –Q "BACKUP DATABASE testing3 TO DISK='C:\Users\Administrator\Desktop\test.bak'"
When I want to create a batch script using the command above in order to create a task scheduler to perform auto backup, it shows error as below:
Here is the batch code:
echo off
c: \
CD "C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn"
SQLCMD -E -S testing\SQLEXPRESS –Q "BACKUP DATABASE testing3 TO DISK='C:\Users\Administrator\Desktop\test.bak';"
I didn't put exit at bottom of it because I want to verify whether the command successfully run or not.
ERROR:
Sqlcmd: 'ûQ "BACKUP DATABASE testing3 TO DISK='C:\Users\Administrator\Desktop\test.bak' ': Unexpected argument. Enter '-?' for help.
Does anyone know how to fix this?
EDIT : I solve it by giving a semi column at the end and type it one by one instead of copy paste it

SQL Server ExpressMaint use account (id/pw)

I am using below batch command for ExpressMaint. I know it has worked with a Windows account.
When I disable the Windows account on the SQL Server instance, it doesn't work correctly.
D:\ExpressMaint\ExpressMaint.exe -S . -D TEST -T CHECKDB -R D:\ExpressMaint\Report -RU WEEKS -RV 4
I get this message
Failed to connect to server ..
Login failed for user 'DPY\gw.lee'. Reason: The account is disabled.
ExpressMaint finished unsuccessfully at 2020-03-09 오후 3:47:32 with Return Code(-3)
Can I have option for specifying ID/PW of SQL Server instance?

Running batch with BCP commands via SQL Server Agent

When I run batch file with:
BCP "SELECT * FROM [KW_GRECOS].[dbo].[V_G076a]" queryout "G:\Bulk\V_G076a_new.bcp" -N -S localhost -T -E
BCP "[KW_GRECOS].[dbo].[hist_V_G076a]" IN "G:\Bulk\V_G076a_new.bcp" -N -S localhost -T -E -b 1000000 -h "CHECK_CONSTRAINTS"
It works perfectly, but when I execute same batch from job in SQL Server Agent:
cmd.exe /c "E:\batch\Bulk_copy.bat"
It's not working:
Date,Source,Severity,Step ID,Server,Job Name,Step
Name,Notifications,Message,Duration,Sql Severity,Sql Message
ID,Operator Emailed,Operator Net sent,Operator Paged,Retries Attempted
12/21/2017 00:40:37,NightBulk,Error,,DBSERVER,NightBulk,,,The job
failed. The Job was invoked by User eTour\ITcom. The last step to
run was step 1 (1 Bulk insert). The job was requested to start at
step 1 (1 Bulk insert).,00:00:00,0,0,,,,0 12/21/2017
00:40:37,NightBulk,Error,1,DBSERVER,NightBulk,1 Bulk insert,,Executed
as user: DBSERVER\ITcom. C:\Windows\system32>BCP "SELECT * FROM
[KW_eTour].[dbo].[V_G075a]" queryout "G:\Bulk\V_G075a_new.bcp" -N -S
localhost -T -E SQLState = S1000 NativeError = 0 Error =
[Microsoft][ODBC Driver 11 for SQL Server]Unable to open BCP host
data-file. Process Exit Code 1. The step failed.,00:00:00,0,0,,,,0
It is due to insufficient permissions.
The SQL Server Agent service-user can not access the file G:\Bulk\V_G075a_new.bcp.
You have the following options:
Move the file to a location where the service-user can access it.
Modify the NTFS-permissions of the file/folder to allow the SQL Server Agent service-user to access the file

Can't remotely login to a SQL Server database using sqlcmd

I am trying to connect to a remote database using sqlcmd. I have tried something like this
sqlcmd -U <ComputerName>\Administrator -P adminpassword -S *.*.*.* -d mydatabase
But this is causing an error:
Failed to Login failed for user '\Administrator'
If I log onto the server where my database and run the command, it won't let me log in, either. But if I go into my SQL Server database and create a SQL Server user and run the same command with those details, I can log in.
But what I want to do is log in via the Administrator user from a different machine. Does anyone see what I'm doing wrong?
With Windows credentials you should use -E:
sqlcmd -E -S *.*.*.* -d mydatabase

How do you execute large SQL Server script file?

I am trying to execute a large SQL Server script file from the command prompt as its not loading in Management Studio. I am using this command
sqlcmd -S .\SQLEXPRESS -U ttandel -P ''
-d [Zen.Databases.Suite]
-i D:\NewMachine\COM.B_Address.Table.sql
Note: password is blank. I have tried all the options for keeping password as blank such as ("",'', ) but nothing is working.
Can anyone please suggest how to do this?
From comment:
I tried with this
sqlcmd -S .\SQLEXPRESS -E
-d [Zen.Databases.Suite]
-i D:\NewMachine\COM.B_Address.Table.sql
This is throwing an error
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login failed for user 'NAPG\ttandel'..
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Cannot open database "[Zen.Databases.Suite]" requested by the login. The login failed..
My Server Security information as below.
The following SQL command will do the work.I have used it multiple times for installing 100 million to 200 million records in DB.
sqlcmd -S Krishneil-PC -E -i C:\Users\Krishneil\Desktop\Script.sql
change Krishneil to your suitability.
Change -d [Zen.Databases.Suite] to -d "Zen.Databases.Suite"

Resources