I am trying to run an MSSQL script using sqlcmd
on Windows 10. The command is something like this:
sqlcmd -S "host" -U "user" -P "password" -d "database" -C -i "script.sql" -I
where the values here are dummy values.
I’m getting the message:
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Data source name not found and no default driver specified.
I didn’t set up the system, so I don’t know how everything has been installed, but I assume that the sqlcmd
was installed with SQLServer Express.
When I check the version, I get:
Microsoft (R) SQL Server Command Line Tool
Version 14.0.2052.1 NT
Copyright (C) 2017 Microsoft Corporation. All rights reserved.
I checked the installed drivers and got:
I don’t know where to go from here. Is it possible to get sqlcmd
to use the relevant driver? Why is it looking for version 13 anyway?
-
1This question is similar to: Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Data source name not found and no default driver specified. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.Charlieface– Charlieface2025年06月11日 00:40:58 +00:00Commented Jun 11 at 0:40
2 Answers 2
Is it possible to get sqlcmd to use the relevant driver? Why is it looking for version 13 anyway?
No, each version of SQLCMD is compiled with a specific driver and requires that driver to be available.
I don’t know where to go from here.
Install ODBC 13 or install a later version of the client tool utilities that supports ODBC 17.
-
Perhaps a later BCP version is already installed but not first in the path. I believe the ODBC 17 version location is
C:\Program Files\Microsoft SQL Server\Client SDK\ODBC170円\Tools\Binn\bcp.exe
Dan Guzman– Dan Guzman2025年06月10日 21:22:33 +00:00Commented Jun 10 at 21:22 -
It's definitely possible, we'd need their PATH variable to really know.Sean Gallardy– Sean Gallardy2025年06月10日 21:31:58 +00:00Commented Jun 10 at 21:31
-
See my answer on how I solved this.Manngo– Manngo2025年06月14日 23:10:41 +00:00Commented Jun 14 at 23:10
The simplest solution is to use the sqlcmd.exe
matched to the installed drviver:
"C:\Program Files\Microsoft SQL Server\Client SDK\ODBC170円\Tools\Binn\sqlcmd.exe" -S "host" -U "user" -P "password" -d "database" -C -i "script.sql" -I
The default sqlcmd
on the path was presumably an older one from a separate install.
-
"I have no idea where that other sqlcmd came from....." We do not even know where it is located, but ignoring it should not be the way to go ...Luuk– Luuk2025年06月14日 11:46:12 +00:00Commented Jun 14 at 11:46
-
To find out where is is do, on a command prompt, this:
WHERE sqlcmd.exe
. (It will search the PATH and report al locations where the file is found)Luuk– Luuk2025年06月14日 11:47:41 +00:00Commented Jun 14 at 11:47 -
@Luuk You misinterpret the statement. As in the question, I didn’t set up the system, so I don’t know how the other
sqlcmd
got there. Of course I know where it is, and I know about theWHERE
command.Manngo– Manngo2025年06月14日 23:09:37 +00:00Commented Jun 14 at 23:09