I would like to be able to open PGadmin4, connect to a server/database and open an sql file using only command line (Windows).
Is there a way to do that ?
Opening pg admin is fairly simple :
start "" /B "C:\Program Files\PostgreSQL\12\pgAdmin 4\bin\pgAdmin4.exe"
but I don't seem able to find a way to connect to the appropriate server/database and open the sql file I want
I'm writing a .bat file to automate the initial opening of a bunch of application for a development project (django)
Try running following command:
Connect to a specific database:
\c database_name;
For example, the following command connects to the dvdrental database:
\c dvdrental;
You are now connected to database "dvdrental" as user "postgres".
For other commands, visit: https://www.postgresqltutorial.com/postgresql-cheat-sheet/
Related
I have setup SQLExpress on a Windows 10 PC and trying to access it via another PC.
I also configured my setup using this guide.
I was able to connect using SQL Server Authentication.
However, when I tried connecting using Windows Authentication, I received the following message:
The login is from an untrusted domain and cannot be used with integrated authentication.
Is there a step I might have missed?
You may need to launch your SSMS under a different set of credentials (runas) in order for it to connect via windows authentication. One way to do this is to create a simple batch file (or shortcut) to do so.
Create a batch file on your desktop and name it something like:
AltSsms.bat
Add the following line to the AltSsms.bat file:
runas.exe /netonly /user:{domain}\{username} "C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe"
Be sure to replace {domain} and {username} with the actual values expected by the remote computer, and provide the full path to your local SSMS installation. I've provided my SSMS path for reference.
Save the updates to the batch file and then double-click it to open it. You should be prompted to enter the password for the {domain}\{username} you specified in the batch file.
Once SSMS loads (and assuming you've entered proper credentials), attempt to connect to the SQL Server instance with Windows Authentication. I've had to do this with several SSIS setups.
I am trying to log in to a remote MS SQL Server 2012 by using SSMS and I'm opening SSMS via command line. When I run my command SSMS starts up and it opens my .sql file that I specify but it doesn't actually log in to my database. Here's the two versions of my command that I've run:
"C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\Ssms.exe"
-S 172.18.211.76 -U USERNAME -P PASSWORD -nosplash "full_path_to_my_.sql_file"
and
"C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\Ssms.exe"
"full_path_to_my_.sql_file" -S 172.18.211.76 -U USERNAME -P PASSWORD -nosplash
Both commands start SSMS successfully and open my .sql file, but neither commands actually logs into my database for me. What I mean by that is that after I run my command the object explorer in SSMS looks like this:
so before I can do anything in my database I have to click on the connect icon and enter my credentials so the object explorer now looks like this:
In the past I was doing this and if I remember correctly I was able to use a command prompt to open SSMS and have it log into a database all at once but I can't find the command that I used to do it previously. If someone could help me out I'd greatly appreciate it. Thanks in advance.
EDIT: here's the version of SSMS I'm using, just in case it's important:
Microsoft SQL Server Management Studio 13.0.15600.2
After looking at this further I have 2 observations:
I didn't specify the name of the database I wanted to connect to in my command using
the -d switch.
I checked and either way, using the -d switch or without, even though the object
explorer doesn't show that I have an active connection I can still run the .sql file
that I specified to be loaded.
So, I guess the problem isn't necessarily that the command I listed doesn't connect to the database, the problem is that a connection is made but it isn't reflected in the object explorer. Thanks everyone.
EDIT: as #larnu pointed out I was running an older version of SSMS. I installed v17.9.1 and tried to run the command but got the same result, after the command is run a connection is made to the database but it is not reflected in the object explorer. Not having the connection display in the object explorer is minor seeing as the connection is actually made and statements can be run in SSMS successfully after SSMS has been opened by the command.
How to create a batch file to connect to Remote desktop and launch Microsoft Sql server and run some scripts.
I tried creating a batch file to connect to using
#ECHO OFF
mstsc /v:"SERVERNAME"
But i was not able to pass username and password
Can anyone advise on this.
EDIT
psexec \\remotemachine-u username -p password ipconfig
Above one connects me to the remote machine and prints its Ip details.
Now I am trying to execute SQL script which is in D:\ of remote machine to execute in Microsoft SQL server (connection) in the remote machine.
Is that possible.
You can use MSTSC to create the connection, with credentials (be sure to check the box that says "Allow me to Save Credentials"), then save that information to an .RDP file
After you should be able to launch:
mstsc "MyConnectionFile.rdp"
In the connection configuration, there is also a tab: "Programs / Start the following programs on connection", which should get your scripts going.
In general, the issue is to set up everything via the GUI, save it to an RDP file, and use that file in the future.
I'm looking to open specific .sql files that have multiple select statements on specific servers at startup in SQL Server Management Studio 2014.
For example, I want to open file 'EmQueries.sql' when I open server sqlemdata9. When I open server sqlplant2, I would like to see file 'PlantQueries.sql' open at startup.
How can I accomplish something like this?
You can achieve the following procedure with Command Line Process, will help you connect to different databases related to specific files and user credentials.
This is Easy with command line (cmd)
ssms "C:\Users\Wizard\Documents\SQL Server Management Studio\query.sql" -S ServerAddressOrIP -d Database -U Username -P Passwordhere
Copy the following line to (.bat) batch file format and run it.
I am using Remote Desktop Connection Manager 2.2
Do u guys know if there's a way to run a .bat/.cmd script (e.g. vpn script) before connecting to a VM?
I have a bat script to connect to Juniper VPN. I wish rdcman run it automatically before connecting so that I wouldn't have to run it every time manually.
Thank u.
You could start Remote Desktop Connection manager from the "VPN" batch file, by appending the following command to your batch file:
mstsc /v VMNAME
This will launch a session with VMNAME.