This is my first time trying to setup mssql server under linux server.
This is my error
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed.
The login is from an untrusted domain and cannot be used with
Integrated authentication..
I could login using "sa" and password
Once I use sqlcmd -E -S linuxsqlserver or sqlcmd -S linuxsqlserver I received the error above.
I followed 2 guide in the link
https://www.mssqltips.com/sqlservertip/5075/configure-sql-server-on-linux-to-use-windows-authentication/
https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-active-directory-authentication?view=sql-server-2017
My current system
Ubuntu 18.04
MSSQL
Window Server 2016
AD
What I have done:
join domain (the domain name is Test1)
Creating the Service Principal Name
setspn -a MSSQLSvc/linuxsqlserver.TEST1.COM:1433 sqllinux
Creating the Keytab File for the SQL Server Service
kinit sqllinux#TEST1.COM
kvno MSSQLSvc/linuxsqlserver.TEST1.COM:1433#TEST1.COM (returned 2)
sudo ktutil
addent -password -p MSSQLSvc/linuxsqlserver.Test1.COM:1433#Test1.COM -k 2 -e aes256-cts-hmac-sha1-96
addent -password -p MSSQLSvc/linuxsqlserver.Test1.COM:1433#Test1.COM -k 2 -e rc4-hmac
wkt /var/opt/mssql/secrets/mssql.keytab
quit
Setting up Active Directory Authentication for SQL Server
/opt/mssql/bin/mssql-conf set network.kerberoskeytabfile /var/opt/mssql/secrets/mssql.keytab
systemctl restart mssql-server
Thank you in advance.
Related
Cannot connect to mssql localhost instance via Azure Data Studio. Get: 'login failed for user sa'.
In the same time I'm able to successfully connect via terminal: mssql -u sa -p myPassword
mssql is in docker with status up
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=myPassword" -p 1433:1433 --name sql1 -h sql1 -d mcr.microsoft.com/mssql/server:2019-latest
os: ubuntu 20.04
firewal is off
I'm sure that pwd is correct, as I can connect to mssql via terminal. Is it Azure settings? Or ubuntu?
Thank you in advance!
I was able to connect to sql instance via Azure Data Studio after change the password. I was using special characters (#, #, $) that might have caused the problem.
After altering password that doesnt iclude special characters it starts working!
My Docker linux SQL Server is not working today at my machine.
I am not sure if this is firewall (I have off them all), or Docker settings (as I just upgraded to the latest Docker version), or a Docker SQL Server issue (but this was working fine on the same machine earlier).
Could anyone help?
I have tried using bash,
/opt/mssql-tools/bin/sqlcmd -S localhost,8010 -U SA -P Test123!
Error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
The docker compose file
version: '3'
services:
mssql:
network_mode: lsvc
image: microsoft/mssql-server-linux:2017-latest
container_name: mssql
hostname: mssql
volumes:
- ./.db:/var/opt/mssql/
- /var/opt/mssql/data
- ./sqlinit.sql:/scripts/sqlinit.sql
ports:
- 8010:1433
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=Test123!
command:
- /bin/bash
- -c
- |
# Launch MSSQL and send to background
/opt/mssql/bin/sqlservr &
# Wait for it to be available
echo "Waiting for MS SQL to be available"
/opt/mssql-tools/bin/sqlcmd -l 30 -S mssql -h-1 -V1 -U sa -P Test123! -Q "SET NOCOUNT ON SELECT \"YAY WE ARE UP\" , ##servername"
is_up=$$?
while [ $$is_up -ne 0 ] ; do
echo -e $$(date)
/opt/mssql-tools/bin/sqlcmd -l 30 -S mssql -h-1 -V1 -U sa -P Test123! -Q "SET NOCOUNT ON SELECT \"YAY WE ARE UP\" , ##servername"
is_up=$$?
sleep 1
done
# Run every script in /scripts
# TODO set a flag so that this is only done once on creation,
# and not every time the container runs
#for foo in /scripts/*.sql
/opt/mssql-tools/bin/sqlcmd -S mssql -U sa -P Test123! -l 30 -e -i /scripts/sqlinit.sql
#done
# So that the container doesn't shut down, sleep this thread
sleep infinity
I would suspect that the mssql instance had failed to start.
Looking at your docker file when the server fail to start it runs into in infinite loop. I would advice you to limit the number of retries on the loop so you will have an indication that the server is failing on startup.
Or better consider the use of the HEALTHCHECK option and not the loop script
see https://blog.couchbase.com/docker-health-check-keeping-containers-healthy/
To troubleshooting the problem try
docker logs <mssql-container-id>
if this doesn't provide enough information try connecting to the container as this was a simple machine.
docker exec -it <mssql-container-id> bash
Look for errors in /var/opt/mssql/log/errorlog
See https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-troubleshooting-guide?view=sql-server-ver15
i found the root cause, it is not due to docker mssql linux
but the latest Docker Desktop Community 2.2.0.0
after uninstall it then downgrade to old version, Docker Desktop Community 2.1.0.5.
it is working now, connect to mssql success.
not sure what is new in latest docker desktop, anyway...i will use old version now.
also one important point to take note, the ".db" folder (windows path where the yml file reside), must deleted before build the docker image.
I am having quite a few problems making MSSQL drivers work in Ubuntu. I have followed the following tutorial to make sqlcmd work in Ubuntu 16.04.
# In CMD:
sqlcmd -S my_server_name -U my_username -P my_password -d my_database
1> select name from sys.databases
2> go
After installing the same tool in Ubuntu, it seems to work, but it timeouts when attempting to connect to the same database:
# In Ubuntu bash
sqlcmd -S my_server_name -U my_username -P my_password -d my_database
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2AFA.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
I have tried to change configurations of the database, such that the port is static at 1433, but still no luck.
Do you have any suggestions?
I have fixed the problem!
1. Install MSSQL drivers on Ubuntu
Follow this tutorial.
2. Ensure your port on the database is static
Follow this tutorial to set up a static port.
3. Identify the IP adress of your database
I had to call the following code on the database to get the ip-adress: local_net_address.
SELECT
+ CONNECTIONPROPERTY('net_transport') AS net_transport,
+ CONNECTIONPROPERTY('protocol_type') AS protocol_type,
+ CONNECTIONPROPERTY('auth_scheme') AS auth_scheme,
+ CONNECTIONPROPERTY('local_net_address') AS local_net_address,
+ CONNECTIONPROPERTY('local_tcp_port') AS local_tcp_port,
+ CONNECTIONPROPERTY('client_net_address') AS client_net_address
4. Connect to database (in Ubuntu bash)
Here are two examples with netcat and sqlcmd.
# Using MSSQL tool
sqlcmd -S my_server_ip_adress//my_server_name,my_port -U my_username -P my_password -d my_database
# Using netcat
nc -z -v -w5 my_server_ip_adress my_port
I'm trying to connect my local/host machine SQL Server from Laravel vagrant homestead. I've been googling all day trying to connect the host machine's database installing different PHP packages but so far have no lucks. I thought I would remove PHP at this point and try to establish the connection inside homestead using sqlcmd instead.
So, I have installed sqlcmd in homestead and tried to execute the following command to connect to the host machine's database.
sqlcmd -S 10.0.2.2,1433 -U sa -P 'password' -Q "sp_databases"
However, I received the following error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection because an error was encountered during handshakes before login. Common causes include client attempting to connect to an unsupported version of SQL Server, server too busy to accept new connections or a resource limitation (memory or maximum allowed connections) on the server..
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2746.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection due to prelogin failure.
However, If I use sqlcmd on my host machine and execute the following command, I am able to access the database.
sqlcmd -S LAPTOP-ACQES\MSSQL2017 -U sa -P Asdf1234 -Q "sp_databases"
In my Homestead.yaml, I have set up port forwarding from:
ports:
- send: 1433
to: 1433
You say this doesn't work:
sqlcmd -S 10.0.2.2,1433 -U sa -P 'password' -Q "sp_databases"
Yet this does:
sqlcmd -S LAPTOP-ACQES\MSSQL2017 -U sa -P Asdf1234 -Q "sp_databases"
In the former, you are using the IP, but no instance name.
Try:
sqlcmd -S 10.0.2.2\MSSQL2017 -U sa -P 'password' -Q "sp_databases"
Also:
Ensure TCP/IP is enabled in SQL Network Configuration.
Verify SQL Server Browser is running.
Allow remote connections in SQL Server properties.
Lock SQL Network configuration to port 1433 on all adapters, and disable dynamic ports (then restart services).
I have installed MSSQL Server 2017 on Ubuntu 16.04.
Now, I must change password.
I know that I can change password using the following commands:
sudo systemctl stop mssql-server
sudo /opt/mssql/bin/mssql-conf set-sa-password
But! I need to change password via script.
Ok. To solve this problem, I had installed "expect" and had wrote script:
#!/bin/bash
/usr/bin/expect <<EOD
spawn sudo /opt/mssql/bin/mssql-conf set-sa-password
expect "password:"
send "Pa$$wo4d!\r"
expect "password:"
send "Pa$$wo4d!\r"
interact
EOD
Double password - password+confirmation.
I have run the script:
ubuntu:~# bash 1.sh
spawn sudo /opt/mssql/bin/mssql-conf set-sa-password
Enter the SQL Server system administrator password:
Confirm the SQL Server system administrator password:
But it does not work. When I try to connect to mssql server, I got an error:
ubuntu:~# /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P Pa$$wo4d!
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login failed for user 'SA'..
OK, let's try a Windows authorization:
ubuntu:~# /opt/mssql-tools/bin/sqlcmd -S localhost -E -C
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : SSPI Provider: No
Kerberos credentials available.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Cannot generate SSPI context.
I can't connect to MSSQL Server until I change my password!
And!
I need to change password via script only.
Can somebody help me please?
More easiest way:
sudo MSSQL_SA_PASSWORD=${Password} /opt/mssql/bin/mssql-conf set-sa-password
Solve the problem via script:
#!/usr/bin/python
import pexpect
ssh_cmd = '/opt/mssql/bin/mssql-conf set-sa-password'
timeout=30
child = pexpect.spawn(ssh_cmd, timeout=timeout)
child.expect(['password:'])
child.sendline('Pa$$wo4d!')
child.expect(['password:'])
child.sendline('Pa$$wo4d!')
child.expect(pexpect.EOF)
child.close()
if 0 != child.exitstatus:
raise Exception(stdout)