Command line that opens SSMS not actually logging into database - sql-server

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.

Related

How to launch pgadmin4 and open a sql file in windows cmd?

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/

How to open .sql file at startup in SQL Server Management Studio?

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.

SQL Server, I can execute sqlcmd with trusted connection but not sqlpackage

We have some deployment scripts that use a combination of dacpacs through sqlpackage and straight scripts using sqlcmd.
When I execute the sqlpackage dac\sqlpackage.exe /p:BlockOnPossibleDataLoss=False /p:BackupDatabaseBeforeChanges=True /a:Publish /sf:.\somedeploy.dacpac /tcs:"Data Source=MyDB;Initial Catalog=MyCatalog;Trusted_Connection=True;"
I get an error message *** Could not deploy package. Unable to connect to target server. I have login auditing turned on in sql and the message I am getting is Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. [CLIENT: 111.222.223.224]
However, I can run our sql scripts through sqlcmd no problem by using the -E argument.
sqlcmd -i Permissions\CreateSqlUser.sql -S MyDB -E
I am running from a commandline that is set to "Run As Administrator" and am currently signed in as the admin. This is running on a Windows Server 2012 VM. I am using sql 2014. We have other installs that haven't had problems but this is our first 2014 install so we are trying to determine if something changed or if we are missing something and if so what.
If I run from profiler I don't see any audit log error messages. I checked the filters and what events I'm listening for and they all look good. Inside sql when I run exec sys.sp_readerrorlog 0, 1, 'Login Failed' I do get the messgaes to show up. (I might be doign something wrong in profiler). Also they show up in the system event logs. I'm not seeing anyplace where it tells me anything about the user attempting to login though.
If don't use trusted connection for sqlpackage and instead use a username and password it works fine. However, part of what our deployment script does is create the users so our preference would be to not do this.

SQL Server 2005 installation from command prompt

I am using following command to install SQL Server 2005 manually.
H:\SQLServer\SQLExpr.exe /ADDLOCAL="All"/INSTANCENAME="SQLEXPRESS"/SAPWD="test123"
It returns no error, but does not acutally install SQL Server too.
First it shows
When I click next, it shows a report
and on clicking OK, it closes. But SQL Server is not installed.
Thanks
A cursory glance of the documentation suggests you need to specify at least one of /qn or /qb on the command line.
The /qn switch suppresses all Setup dialog boxes and error messages. If the /qn switch is specified, all Setup messages, including error messages, are written to Setup log files. For more information about log files, see How to: View SQL Server 2005 Setup Log Files.
The /qb switch allows the display of basic Setup dialog boxes. Error messages are also displayed.
Although I've never had to install SQL Server from the command line before, it seems that simply by reading the documentation it is clear the easiest way to do this is with an options file:
To run a command prompt installation of SQL Server 2005 using an .ini file
Run Setup.exe from the command prompt:
<CD or DVD Drive>\Setup.exe /settings C:/set.ini /qn

Calling bash from PsExec from SQL with xp_cmdshell

I am trying to call a bash command through a user account with PsExec. Cygwin is being used, and I am trying to run a command from SQL:
exec master..xp_cmdshell 'psexec -u cyg_server -p <pwd> -accepteula "bash script.sh"';
However, I get the following error from psexec:
Access is denied.
PsExec could not start bash script.sh:
Any suggestions?
I am using SQL 2005, Windows Server 2008, and Cygwin with fresh binaries
You're probably running this as a SQL user or a user without permissions to that file. My best bet is a SQL user (such as sa). When you do this, the Windows credentials it uses are of the Service Account, which is SYSTEM by default, but could be something else if you set it that way.
If you're just calling this from within SQL, make sure that you are, in fact, running as a Windows user that has permissions to open all of the files necessary.
If this is running in a SQL Server Agent job, you'll need to set up a Credential, and then set up a Proxy. Once you've done that, you can assign the Proxy to run the job (it's the third or fourth drop down on the Job Step dialog), and it will run with the correct Windows credentials.

Resources