sqlcmd execute issue in SQL Server 2025

Ganesh R 20 Reputation points
2026-01-28T16:12:11.7133333+00:00

EXEC xp_cmdshell 'sqlcmd -S MYS-0101 -d SampleDatabase -U sa -P Sa123 -i "script.sql"' is not working in SQL 2025

its giving trust certificate error, how to fix this certificate error without changing the code I need the microsoft recommendation

whether can we trustservercertificate at SQL Configuration level, without changing the code.

SQL Server Database Engine
0 comments No comments
{count} votes

Answer accepted by question author
  1. Erland Sommarskog 132.4K Reputation points MVP Volunteer Moderator
    2026-01-28T21:35:00.37+00:00

    Short story: You can use the -C option to start working. However, from a security standpoint, this not the best solution. There is a better solution - and which does not require code changes. Read on!

    Long story: Microsoft has the last couple of years changed the defaults in their client APIs with regards to encrypted connections, so that now all APIs default to require an encrypted connection.

    Why is this important? The reason you want an encrypted connection, is that you don't want anyone to tap the wire to get the data you are sending to SQL Server, you are receiving through SQL Server. This is known as a man-in-the-middle attack.Furthermore, that man in the middle, may offer you a certificate, and if you blindly trust that certificate, you are still open for that attack. And the attacker may not just only tap the wire, it could also distort the data send to and from the server.

    By default, SQL Server encrypts the data with a self-signed certificate, and there is no way you can gain real trust in this certificate. Instead, you need to install a real certificate. This can be something you create yourself, and you then distribute to computers that need it, and that they can install in their Trusted Certificate Store. This requires some admin job, but the certificate costs zero money.

    The other alternative is to buy a certificate from a trusted vendor like VeriSign, Microsoft etc. For these vendors, a computer normally has their root certificate already installed, and through a chain of certificates, all computers can trust the certificate.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Ganesh R 20 Reputation points
    2026-01-29T09:39:14.29+00:00

    Thanks everyone for the inputs, can please share an article where this breaking changing in SQL 2025 which requires clients to send the servertrustcertificate option explicity, if they are not using any FQDN or certificate.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.