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

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

Related

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?

Can't connect to SQL Server in Docker container

I can connect to SQL Server in a Docker container using...
Docker exec -it 93fc /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Password$$123
But I can't connect if I plug the same details into RazorSQL.
i.e. localhost with SA and Password$$123
What step am I missing?
This is the run command...
Docker run -e 'ACCEPT_EULA=Y' -e SA_PASSWORD=Password$$123 -p 1433:1433 -d microsoft/mssql-server-linux
This is a connection string I've tried from a test running in Visual Studio...
Data Source=localhost;Initial Catalog=master;User=sa;Password=Password$$123;
I think it can find the SQL Server but for some reason it can't login with SA.
Even this running from Windows doesn't work...
sqlcmd -S 192.168.10.79,1433 -U SA -P Password$$123
This problem goes away if I update the password using...
ALTER LOGIN SA WITH PASSWORD='Pa$$word123'
So I can connect to SQL Server inside the container using the initial password and then if I change the password I can connect externally.
How can the password determine if an external connection works?
If I enter env in the console, I get...
MSSQL_SA_PASSWORD=Password14961123
I presume that was auto generated.

Connecting to SQL Server Express from within Docker Container gives an error occurred evaluating the password

I am trying to run a docker container from the Microsoft SQL Server Express image (https://hub.docker.com/r/microsoft/mssql-server-windows-express/)
For example I've tried the following commands (I'll use the -d flag once I've got it working)
docker run -it -p 1433:1433 -e SA_PASSWORD=Mfp_4871nJUj_1-23H -e ACCEPT_EULA=Y --name to_delete_1 microsoft/mssql-server-windows-express powershell.exe
docker run -it -p 1433:1433 -e 'SA_PASSWORD=Mfp_4871nJUj_1-23H' -e 'ACCEPT_EULA=Y' --name to_delete_1 microsoft/mssql-server-windows-express powershell.exe
(not the real password - I've tried many passwords since one of the suggestions for fixing the error I see below is to ensure that the password meets Microsoft's password policy. However for all passwords I get the same error)
I've also tried lower case sa_password
However, each time I try to connect with the sa account from within the container using any of
sqlcmd -U sa -P Mfp_4871nJUj_1-23H
sqlcmd -S localhost -U sa -P Mfp_4871nJUj_1-23H
sqlcmd -S localhost\sqlexpress -U sa -P Mfp_4871nJUj_1-23H
sqlcmd -U sa
sqlcmd -S localhost -U sa
sqlcmd -S localhost\sqlexpress -U sa
(entering password for last 3)
I get
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login failed for user 'sa'..
Looking at the SQL Server logs it shows
2017-03-13 21:25:52.32 Logon Error: 18456, Severity: 14, State: 7.
2017-03-13 21:25:52.32 Logon Login failed for user 'sa'. Reason: An error occurred while evaluating the password. [CLIENT: 172.22.251.6]
The main advice is to ensure the password meets SQL Server's password criteria but I think all of the passwords I've tried do.
I run Docker on Windows 10 Enterprise (build 14393.693).
I have Docker for Windows Version 17.03.0-ce-win1 (10300).
What do I need to do to be able to connect to SQL Server from within the container using the microsoft/mssql-server-windows-express Docker imamge?
Thanks
I don't know if you ever found the answer to this question. I have not tried connecting to the database from within the container, but I have connected to it from SSMS from outside the container. The key for me was to specify the password in double quotes in the original command. The final command looked like this:
docker run -d -p 1433:1433 -e sa_password="useComplexPasswordHere" -e ACCEPT_EULA=Y microsoft/mssql-server-windows-express
I was then able to connect to it through SSMS. Get the IP address from the docker container using:
docker inspect
Then log in to the database through SSMS like this:
SSMS Login info

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"

Install and connect to database with psql

I want to set up the psql terminal tool in Centos 6.6
I have been given access to as database and i just want to use the terminal for writing queries to the database for information. I have no prior experience with psql before but I want to move on from the pgadmin3 gui.
I started off by installing psql:
yum install postgresql
but when I try to access it, ie. typing [root#localhost]# psql I get the following error:
psql: FATAL: database "root" does not exist
I've tried using:
psql --host=<DB instance endpoint> --port=<port> --username=<master user name> --password --dbname=<database name>
but that fails to work too, maybe this is really basic but im completely lost for setting this up
Use:
psql -U my_pgadmin_username postgres
or
psql -U my_pgadmin_username -h localhost postgres
Alternately, more typical usage:
sudo -u postgres psql

Resources