I want to make a link that would run ssms.exe , login and open a .sql file.
However this: SSMS.exe -E -d AB2014 work fine
when this SSMS.exe -E -d AB2014 "C:\Users\Kazz\Desktop\AB2014\SQLQuery.sql" opens the .sql 'file' but fails to login...
For my money, the tool to use when I just want to run a file (instead of have an interactive session with the server) is sqlcmd.exe. In your situation, it'd go something like:
sqlcmd -E -d AB2014 -i "C:\Users\Kazz\Desktop\AB2014\SQLQuery.sql" -S someServer
Related
In SQL Server, if I want to run a script from the command line, I can do this
/opt/mssql-tools/bin/sqlcmd -S $DB_HOST -U $DB_USER -P $DB_PASS -d $DB_NAME -i myscript.sql
Is it possible to run just a single command without a script and get the results? For instance, if I just wanted to run
SELECT 1
How would I do that from the command line?
I think you want the -q switch:
sqlcmd -S localhost -U MyUser -P MyPass -d MyDb -q "SELECT 1"
Documentation is here
Given that you want to:
run just a single command without a script and get the results
Another possible answer would be to run:
sqlcmd -S localhost -U MyUser -P MyPass -d MyDb -Q "SELECT 1"
That is with a capital -Q.
This will run the command and then exit, allowing you to read the error code result.
The answer above uses lowercase -q, which will run the command but leave the sqlcmd prompt open and running.
Depending on what you want, the case of the -Q/-q argument matters.
Its almost certain that HTA files are obsolete, but i've found that they are much better than net send / msg.
I'm trying to run a HTA file on a remote machine using PSTools, but instead of it running, it brings back a broken window:
Running the HTA file using CMD (locally) works perfectly though.
My PsExec line:
PsExec.exe -accepteula -i -d \\itwall cmd 'mstha \\intranet\Downloads\VisitorSystemNewMessage.hta asd'
I even tried to run the HTA from a Batch file, but the exact same thing happens.
Any ideas?
It's because the account running the command cannot interact with the session of the remote user.
Use the -s switch to run the HTA using the system account of the remote computer.
Also, you shouldn't need to run cmd. You should be able to just specify mshta.exe then your arguments.
PsExec.exe -accepteula -s -i -d \\itwall mshta.exe \\intranet\Downloads\VisitorSystemNewMessage.hta asd
Edit: To illustrate that this is not an HTA issue. Run the following command:
PsExec.exe -accepteula -i -d \\itwall notepad.exe
Notice you'll have the same black window showing.
I have followed this question to build a batch file to run the PuTTYwith my username and password:
How to run a command file in PuTTY using automatic login in a command prompt?
#echo off
START putty.exe -ssh [domain] -l [username] -pw [password] -m code.txt
#echo
And the PuTTY will try to run the code.txt file, which have the following code:
HResults -p -e "???" sil -e "???" sp -L labels/test lib/words3 results/*.rec
read
It will show a matrix. I try to run the batch file, it is able to open PuTTY, login and run the command in text file. But the output in PuTTY terminal is a mess. The layout of output is fine, when I doing those things manually. Is that mean some kind of setting is missing? It's not making any sense a batch file will change the output of another application...... Thanks
The -m switch imply a non-interactive session. While, when logging in manually, an interactive mode is used by default.
It may fundamentally affect output of some applications.
Try forcing the interactive mode using the -t switch:
START putty.exe -ssh [domain] -t -l [username] -pw [password] -m code.txt
I have an SQL script file which it has big size " 1.4 GB "
when I try to open it in SQL SERVER Management Studio
it fails and give me message
The System can't find the file specified
when I try to open it with notepad++
file is too big to be opened by notepad++
so does it there anyway to open this script ?
Run this command in Command prompt by providing the required details. This command would execute the SQL file without opening the file.
sqlcmd -S <ServerName> -U <LoginUser> -P <Password> -d <DatabaseName> -i <Inputfilenamewithpath> -o <Outputfilenamewithpath>
i used below command to backup my database
sudo -u user_name pg_dump dbName -f /home ..../someWhere/db.sql
but it gives me this :
pg_dump: [archiver] could not open output file "/home ..../someWhere/db.sql": Permission denied
after googling this issue i find that i must backup my data under the /tmp path , but doesn't work
how can i resolve this issue ?
thanks in advance,
i am using Ubuntu 12.04 lts
It looks like your pg_dump is working fine, but it is having problems opening the output file as the sudo user. Just guessing, but, if you do the redirection as the user (presumably the one running the pg_dump command) id, that should do it, that is:
sudo -u user_name pg_dump dbName > /home ..../someWhere/db.sql
Using this technique your pg_dump will run as the postgres user (assuming that is who user_name is) and the file being written in /home... will be written using the permission of the user running the command (this user might have different permissions than the postgres user).
try pg_dump from psql command-line as below:
postgres=# \! pg_dump dbName -f /home ..../someWhere/db.sql
Do it from psql command line like below
-bash-4.1$ pg_dump -Fp dbName -f /home ..../someWhere/db.sql &
-F selects the format of the output in which p is Output a plain-text SQL script file
and & at the end will run your backup in the background.
Just in case somebody else lands here like I did, be aware that pg_dump shows this error too if the folder doesn't exist. In that case, just create the directory beforehand using mkdir -p folder_name.