How to connect to SQL Server using sqlcmd on Linux?Connect to LocalDB via SQLCMD in PowerShellConnecting to...
Can "ee" appear in Latin?
How can I differentiate duration vs starting time
Discouraging missile alpha strikes
Proof of an integral property
Have any astronauts or cosmonauts died in space?
Is opening a file faster than reading variable content?
How to play songs that contain one guitar when we have two or more guitarists?
How do I add a strong "onion flavor" to the biryani (in restaurant style)?
Why do we divide Permutations to get to Combinations?
What is the correct way to shuffle?
How bad is a Computer Science course that doesn't teach Design Patterns?
Why would you use 2 alternate layout buttons instead of 1, when only one can be selected at once
Is layered encryption more secure than long passwords?
Can you wish for more wishes from an Efreeti bound to service via an Efreeti Bottle?
Buying a "Used" Router
What does “to the numbers” mean in landing clearance?
Which was the first story to feature space elevators?
boss asked me to sign a resignation paper without a date on it along with my new contract
Is it appropriate to give a culturally-traditional gift to a female coworker?
Why didn't Lorentz conclude that no object can go faster than light?
Short story where Earth is given a racist governor who likes species of a certain color
Sing Baby Shark
Why is ra lower than re while la is higher than le?
Is it possible to detect 100% of SQLi with a simple regex?
How to connect to SQL Server using sqlcmd on Linux?
Connect to LocalDB via SQLCMD in PowerShellConnecting to SQL Server 2014 with sqlcmdConnecting to SQL Server from R which is Running on Remote UNIX MachineCan not connect to SQL Server from Ubuntu sqlcmd clientMSSQL on linux c++ connected timeoutCannot connect PHP to SQL Server in no wayThe system cannot find the file specifiedUnable to access an SQL Server 2016 named instance locally via sqlcmd when only using @@SERVERNAME valueError connecting to MSSQL server from Linuxhelp in connecting the sql server 2017 developer edition
I have set up the Microsoft ODBC Driver 13 for SQL Server on an Ubuntu 16.04 machine. I am now trying to test a database connection, that includes both the server name and an instance name.
The following both work fine from a Windows machine:
sqlcmd -S "SERVERNAMEINSTANCENAME" -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
sqlcmd -S SERVERNAMEINSTANCENAME -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
However none of them work on Linux - they all return the error message below. The error implies the server cannot be found:
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : MAX_PROVS: Error Locating Server/Instance Specified [xFFFFFFFF]. .
Sqlcmd: Error: Microsoft ODBC Driver 13 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 also tried escaping the backslash with the same error (and with single and double quotes).
sqlcmd -S "SERVERNAME\INSTANCENAME" -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
sqlcmd -S SERVERNAME\INSTANCENAME -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
The driver is working however as I can connect to a different server with no instance name:
sqlcmd -S SERVERNAME -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
I am fairly certain it is due to the backslash, but cannot find a way to get around this.
sql-server linux ubuntu sqlcmd
add a comment |
I have set up the Microsoft ODBC Driver 13 for SQL Server on an Ubuntu 16.04 machine. I am now trying to test a database connection, that includes both the server name and an instance name.
The following both work fine from a Windows machine:
sqlcmd -S "SERVERNAMEINSTANCENAME" -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
sqlcmd -S SERVERNAMEINSTANCENAME -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
However none of them work on Linux - they all return the error message below. The error implies the server cannot be found:
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : MAX_PROVS: Error Locating Server/Instance Specified [xFFFFFFFF]. .
Sqlcmd: Error: Microsoft ODBC Driver 13 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 also tried escaping the backslash with the same error (and with single and double quotes).
sqlcmd -S "SERVERNAME\INSTANCENAME" -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
sqlcmd -S SERVERNAME\INSTANCENAME -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
The driver is working however as I can connect to a different server with no instance name:
sqlcmd -S SERVERNAME -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
I am fairly certain it is due to the backslash, but cannot find a way to get around this.
sql-server linux ubuntu sqlcmd
2
Have you tried connecting using a port specification rather than instance name (e.g.-S "SERVERNAME,port"
)?
– Dan Guzman
Aug 18 '16 at 11:26
@DanGuzman - thanks! That approach works. Will I add details as an answer?
– geographika
Aug 18 '16 at 11:46
add a comment |
I have set up the Microsoft ODBC Driver 13 for SQL Server on an Ubuntu 16.04 machine. I am now trying to test a database connection, that includes both the server name and an instance name.
The following both work fine from a Windows machine:
sqlcmd -S "SERVERNAMEINSTANCENAME" -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
sqlcmd -S SERVERNAMEINSTANCENAME -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
However none of them work on Linux - they all return the error message below. The error implies the server cannot be found:
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : MAX_PROVS: Error Locating Server/Instance Specified [xFFFFFFFF]. .
Sqlcmd: Error: Microsoft ODBC Driver 13 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 also tried escaping the backslash with the same error (and with single and double quotes).
sqlcmd -S "SERVERNAME\INSTANCENAME" -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
sqlcmd -S SERVERNAME\INSTANCENAME -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
The driver is working however as I can connect to a different server with no instance name:
sqlcmd -S SERVERNAME -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
I am fairly certain it is due to the backslash, but cannot find a way to get around this.
sql-server linux ubuntu sqlcmd
I have set up the Microsoft ODBC Driver 13 for SQL Server on an Ubuntu 16.04 machine. I am now trying to test a database connection, that includes both the server name and an instance name.
The following both work fine from a Windows machine:
sqlcmd -S "SERVERNAMEINSTANCENAME" -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
sqlcmd -S SERVERNAMEINSTANCENAME -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
However none of them work on Linux - they all return the error message below. The error implies the server cannot be found:
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : MAX_PROVS: Error Locating Server/Instance Specified [xFFFFFFFF]. .
Sqlcmd: Error: Microsoft ODBC Driver 13 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 also tried escaping the backslash with the same error (and with single and double quotes).
sqlcmd -S "SERVERNAME\INSTANCENAME" -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
sqlcmd -S SERVERNAME\INSTANCENAME -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
The driver is working however as I can connect to a different server with no instance name:
sqlcmd -S SERVERNAME -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
I am fairly certain it is due to the backslash, but cannot find a way to get around this.
sql-server linux ubuntu sqlcmd
sql-server linux ubuntu sqlcmd
asked Aug 18 '16 at 10:34
geographikageographika
1582212
1582212
2
Have you tried connecting using a port specification rather than instance name (e.g.-S "SERVERNAME,port"
)?
– Dan Guzman
Aug 18 '16 at 11:26
@DanGuzman - thanks! That approach works. Will I add details as an answer?
– geographika
Aug 18 '16 at 11:46
add a comment |
2
Have you tried connecting using a port specification rather than instance name (e.g.-S "SERVERNAME,port"
)?
– Dan Guzman
Aug 18 '16 at 11:26
@DanGuzman - thanks! That approach works. Will I add details as an answer?
– geographika
Aug 18 '16 at 11:46
2
2
Have you tried connecting using a port specification rather than instance name (e.g.
-S "SERVERNAME,port"
)?– Dan Guzman
Aug 18 '16 at 11:26
Have you tried connecting using a port specification rather than instance name (e.g.
-S "SERVERNAME,port"
)?– Dan Guzman
Aug 18 '16 at 11:26
@DanGuzman - thanks! That approach works. Will I add details as an answer?
– geographika
Aug 18 '16 at 11:46
@DanGuzman - thanks! That approach works. Will I add details as an answer?
– geographika
Aug 18 '16 at 11:46
add a comment |
2 Answers
2
active
oldest
votes
With the help of Dan Guzman's comment I got the connection working using a port.
I had a Windows machine with SQL Management Studio connected to the database in question, and used:
netstat -abn
Then I searched for ssms.exe for the connection details:
TCP 192.168.0.31:50777 192.168.0.78:49399 ESTABLISHED [Ssms.exe]
Alternatively log into the database server and look at the ports used by the instance in SQL Server Configuration Manager (SQL Server Network Configuration > Protocols for INSTANCENAME > TCP/IP > Properties > IPAll TCP Dynamic Ports).
The following then both worked:
sqlcmd -S 192.168.0.78,49399 -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
sqlcmd -S SERVERNAME,49399 -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
1
In your second example, isINSTANCENAME
a typo? I think it should beSERVERNAME
. Although the port number specification may be an acceptable work-around for you, I think the instance name should work from Ubuntu as it does from Windows. Make sure UDP 1434 (for the SQL Server Browser service), can be reached using a utility likenetcat
.
– Dan Guzman
Aug 18 '16 at 12:23
add a comment |
It worked like a charm. Thanks for sharing!!
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f147185%2fhow-to-connect-to-sql-server-using-sqlcmd-on-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
With the help of Dan Guzman's comment I got the connection working using a port.
I had a Windows machine with SQL Management Studio connected to the database in question, and used:
netstat -abn
Then I searched for ssms.exe for the connection details:
TCP 192.168.0.31:50777 192.168.0.78:49399 ESTABLISHED [Ssms.exe]
Alternatively log into the database server and look at the ports used by the instance in SQL Server Configuration Manager (SQL Server Network Configuration > Protocols for INSTANCENAME > TCP/IP > Properties > IPAll TCP Dynamic Ports).
The following then both worked:
sqlcmd -S 192.168.0.78,49399 -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
sqlcmd -S SERVERNAME,49399 -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
1
In your second example, isINSTANCENAME
a typo? I think it should beSERVERNAME
. Although the port number specification may be an acceptable work-around for you, I think the instance name should work from Ubuntu as it does from Windows. Make sure UDP 1434 (for the SQL Server Browser service), can be reached using a utility likenetcat
.
– Dan Guzman
Aug 18 '16 at 12:23
add a comment |
With the help of Dan Guzman's comment I got the connection working using a port.
I had a Windows machine with SQL Management Studio connected to the database in question, and used:
netstat -abn
Then I searched for ssms.exe for the connection details:
TCP 192.168.0.31:50777 192.168.0.78:49399 ESTABLISHED [Ssms.exe]
Alternatively log into the database server and look at the ports used by the instance in SQL Server Configuration Manager (SQL Server Network Configuration > Protocols for INSTANCENAME > TCP/IP > Properties > IPAll TCP Dynamic Ports).
The following then both worked:
sqlcmd -S 192.168.0.78,49399 -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
sqlcmd -S SERVERNAME,49399 -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
1
In your second example, isINSTANCENAME
a typo? I think it should beSERVERNAME
. Although the port number specification may be an acceptable work-around for you, I think the instance name should work from Ubuntu as it does from Windows. Make sure UDP 1434 (for the SQL Server Browser service), can be reached using a utility likenetcat
.
– Dan Guzman
Aug 18 '16 at 12:23
add a comment |
With the help of Dan Guzman's comment I got the connection working using a port.
I had a Windows machine with SQL Management Studio connected to the database in question, and used:
netstat -abn
Then I searched for ssms.exe for the connection details:
TCP 192.168.0.31:50777 192.168.0.78:49399 ESTABLISHED [Ssms.exe]
Alternatively log into the database server and look at the ports used by the instance in SQL Server Configuration Manager (SQL Server Network Configuration > Protocols for INSTANCENAME > TCP/IP > Properties > IPAll TCP Dynamic Ports).
The following then both worked:
sqlcmd -S 192.168.0.78,49399 -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
sqlcmd -S SERVERNAME,49399 -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
With the help of Dan Guzman's comment I got the connection working using a port.
I had a Windows machine with SQL Management Studio connected to the database in question, and used:
netstat -abn
Then I searched for ssms.exe for the connection details:
TCP 192.168.0.31:50777 192.168.0.78:49399 ESTABLISHED [Ssms.exe]
Alternatively log into the database server and look at the ports used by the instance in SQL Server Configuration Manager (SQL Server Network Configuration > Protocols for INSTANCENAME > TCP/IP > Properties > IPAll TCP Dynamic Ports).
The following then both worked:
sqlcmd -S 192.168.0.78,49399 -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
sqlcmd -S SERVERNAME,49399 -U User -P pwd -d DatabaseName -Q "SELECT TOP 5 Id FROM dbo.MyTable;"
edited Aug 18 '16 at 12:33
answered Aug 18 '16 at 11:53
geographikageographika
1582212
1582212
1
In your second example, isINSTANCENAME
a typo? I think it should beSERVERNAME
. Although the port number specification may be an acceptable work-around for you, I think the instance name should work from Ubuntu as it does from Windows. Make sure UDP 1434 (for the SQL Server Browser service), can be reached using a utility likenetcat
.
– Dan Guzman
Aug 18 '16 at 12:23
add a comment |
1
In your second example, isINSTANCENAME
a typo? I think it should beSERVERNAME
. Although the port number specification may be an acceptable work-around for you, I think the instance name should work from Ubuntu as it does from Windows. Make sure UDP 1434 (for the SQL Server Browser service), can be reached using a utility likenetcat
.
– Dan Guzman
Aug 18 '16 at 12:23
1
1
In your second example, is
INSTANCENAME
a typo? I think it should be SERVERNAME
. Although the port number specification may be an acceptable work-around for you, I think the instance name should work from Ubuntu as it does from Windows. Make sure UDP 1434 (for the SQL Server Browser service), can be reached using a utility like netcat
.– Dan Guzman
Aug 18 '16 at 12:23
In your second example, is
INSTANCENAME
a typo? I think it should be SERVERNAME
. Although the port number specification may be an acceptable work-around for you, I think the instance name should work from Ubuntu as it does from Windows. Make sure UDP 1434 (for the SQL Server Browser service), can be reached using a utility like netcat
.– Dan Guzman
Aug 18 '16 at 12:23
add a comment |
It worked like a charm. Thanks for sharing!!
New contributor
add a comment |
It worked like a charm. Thanks for sharing!!
New contributor
add a comment |
It worked like a charm. Thanks for sharing!!
New contributor
It worked like a charm. Thanks for sharing!!
New contributor
New contributor
answered 10 mins ago
truthtriumphstruthtriumphs
1
1
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f147185%2fhow-to-connect-to-sql-server-using-sqlcmd-on-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Have you tried connecting using a port specification rather than instance name (e.g.
-S "SERVERNAME,port"
)?– Dan Guzman
Aug 18 '16 at 11:26
@DanGuzman - thanks! That approach works. Will I add details as an answer?
– geographika
Aug 18 '16 at 11:46