Thanks for looking into my post. I am facing issue while connecting SQL Server on Linux using windows authentication account if I use local account then things are working fine without any issue. Please let me know what changes are required here.
ERROR
/opt/mssql-tools/bin/sqlcmd -S aaa.com -U aaa -d master
Password:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'aaa'..
/opt/mssql-tools/bin/sqlcmd -S aaa.com -U 'test' -d master -P Hello1234
1> select ##servername
2> go
Related
I want to connect to a remote SQL Server from WSL2, but I keep getting errors for some reason. I tried connecting using my Windows Host machine without any problem.
~/.odbc.ini
[MSSQLTest]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.9.so.1.1
server=tcp:server,port
Database=Databasename
Trusted_Connection=yes
TrustServerCertificate=yes
uid=username#domain.com
pwd=password
odbcinst -j
unixODBC 2.3.7
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/test/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
Errors
test#Desktop:/mnt/c/Users/test$ isql -v mssqltest
[S1000][unixODBC][Microsoft][ODBC Driver 17 for SQL Server]SSPI Provider: No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1000)
[S1000][unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Cannot generate SSPI context
I tried several different changes in the DSN, but none worked. The only thing that changed was the error messages. Then I tried installing mssql-tools to use sqlcmd, but I got similar errors.
Errors
test#DESKTOP:/mnt/c/Users/test$ sqlcmd -S server -U domain\\username -P password -G
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : SSL Provider: [error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:self signed certificate].
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish the connection.
I have no idea what the error above means.
test#DESKTOP:/mnt/c/Users/test$ sqlcmd -S server#example.com -U domain\username -P password -G
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : SSL Provider: [error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:self signed certificate].
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection.
I get a similar error. If I change something in the DSN, I get an error stating No kerberos credentials available (default cache: FIEL:/tmp/krb5cc_1000). Cannot generate SSPI context.
I looked up and tried many different solutions suggested on SO and other sites, but I can't seem to get it working. I can, however, ping the server.
Why is it doing this? Why does my connection work from my Windows Host machine but not WSL? What am I missing?
I don't think there's anything wrong with your setup. You might want to check if your admin allows SQL Authentication. Then use the sqlcmd to check if it works for you. You may be able to figure out the solution then.
sqlcmd -SXX.XX.XX.XXX -U username -P password -Q "select top 5 * from your_table"
The following connection attempt works!
sqlcmd -S SOMEOTHERPC\SQLEXPRESS,1433 -Q "SELECT * WHERE Lol=1" -d "mydb"
the following does not work, it times out after 10 seconds and fails
sqlcmd -S SOMEOTHERPC\SQLEXPRESS -Q "SELECT * WHERE Lol=1" -d "mydb"
given that 1433 is the default port for sql server, why is it that I have to provide it? used to work without it?
many applications are getting this connection time out issue And i feel it is due to this?
had the default port been changes somewhere in sqlserver config?
EDIT:
Microsoft SQL Server 2014
Windows Embedded Standard 32bit (6.1 Build 7601)
I would like to use the sqlcmd cli on a mac to run a script on a Microsoft SQL Server using Windows Authentication.
Software details:
Mac OS 10.13
MSSQL 2012 version 11.0.2100.60
sqlcmd version 17.0.0001.1 Linux
As a test, I tried:
sqlcmd -S hostname,port\\database_name -U domain\\user.name -P "XXX" -q "select ##version"
But I received the error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user domain\user.name
I also configured a freetds DSN and attempted to connect using:
sqlcmd -S DSN_NAME -D -U domain\\user.name -P "XXX" -q "select ##version"
But I received the error:
The DSN specified an unsupported driver
For what it's worth, I'm able to use the same DSN through isql by doing:
isql DSN user.name password
Any help greatly appreciated!
A few things that might help.
If you want to use Windows Authentication I think that you will have to set up Kerberos and NOT supply the login id and password with the sqlcmd command.
I had a confusing scenario where isql with freetds would connect using username and password when the DB server was set to only receive Windows Authentication connections, but the MS ODBC driver would not connect using the username and password. After connecting my computer to the network, settings up kerberos, and getting a kerberos ticket I was able to connect using:
sqlcmd -S 'ServerName'
When executing any one of the following commands:
osql -E -S ComputerName\InstanceName
osql -E -S ComputerName\InstanceName -i MyScript.sql -o MyOutput.rpt
osql -E -q "SELECT * FROM Northwind.dbo.Shippers"
osql -E -Q "SELECT * FROM Northwind.dbo.Shippers" -o MyOutput.rpt
I am getting the following error:
[SQL Server Native Client 10.0]SQL Server Network Interfaces: Connection
string is not valid [87].
[SQL Server Native Client 10.0]Login timeout expired
[SQL Server Native Client 10.0]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.
However, I am able, without issue to login and run SELECT queries from SSMS.
How do I run queries against SQL Server 2008 using osql?
Do you have your logged in account set up as a user in SQL Server?
I usually work with specific accounts and SQL Server logins instead of Trusted Logins, and then just specify the database coordinates on the command line with the -S, -D, -U, and -P options:
osql -S %SERVERNAME% -U %USERNAME% -P %PASSWORD% -d %DBNAME%
For instance, if your server name is MyServer\SQL2008 and your user name is Foo and your password is Bar and your database is MyDB, then you'd use this:
osql -S MyServer\SQL2008 -U Foo -P Bar -d MyDB
And then continue on with the rest of your options after that.
If you really want to use your Trusted connection, you need to go to SQL Server Management Studio, and ensure your current Widows Login is added as a user and given appropriate permissions to your database, etc.
In SSMS, connect to your server manually (the 'sa' user and password perhaps), and then expand the "Security" node and look at the logins. If your currently logged in Windows User isn't listed, you'll want to right-click, add new Login, and add your current user.
Then you should be able to run with a Trusted Connection.
You have to run all command in a single line
like this
osql -E -S ComputerName\InstanceName -i MyScript.sql -o MyOutput.rpt
or
osql -E -S ComputerName\InstanceName -Q "SELECT * FROM Northwind.dbo.Shippers" -o MyOutput.rpt
Now you have to see if you can log in SQL Server or if the service is up or even if the TCP/IP protocol is enable
Use the value in the Server name: field for ComputerName\InstanceName. (e.g. MYPC\SQLEXPRESS)
Type:
osql -E -S MYPC\SQLEXPRESS
You will see the interactive prompt.
Then enter your commands:
USE pubs
GO
Also, you can use sqlcmd:
sqcmd -E -S MYPC\SQLEXPRESS
I am running the following command in a batch file:
osql -S dbname -U username -P password -i C:\inputSQL.sql -o C:\postMigration.log -n
The dbname, username, and password have all been set correctly.
However , when I run the batch file I get this output to the "C:\postMigration.log" log
[SQL Native Client]Shared Memory Provider: No process is on the other
end of the pipe.
[SQL Native Client]Communication link failure
My question is: what can cause SQL Server 2005 to throw this error? Is it a login issue?
Thanks!
Looks like you miss -H (host) param. Also note -o would work relative server's disk C: