1

I have ps1 script that contains Invoke-Sqlcmd command to execute some sql queries. I am executing this ps1 file from the c# form application with the below code:

var ps1File = @executeChangeScriptPs1FilePath;     
ProcessStartInfo startInfo = new ProcessStartInfo
                {
                    FileName = "powershell.exe",
                    Arguments = $"-NoExit -ExecutionPolicy ByPass -File \"{ps1File}\" \"{args0}\" \"{args1}\" \"{args2}\" \"{args3}\" \"{args4}\"",
                    UseShellExecute = false,
                    Verb = "runas"
                };
    
                Process process = new Process();
                process.StartInfo = startInfo;
                process.Start();
    
                process.WaitForExit();
                process.Close();

But its giving below error on the ps1 window;

Invoke-Sqlcmd : Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=15.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

When I execute Invoke-SqlCmd command from powershell directly its working. But when I execute from C# application giving mentioned error.

Does anyone know how to solve the problem?

Here ss for powershell screens. Left one opened from c# application. Right one opened driectly.

enter image description here

nrllhcinar
  • 109
  • 5
  • downloaded and installed SQL Server Data Tools followed by a reboot – jazb Feb 15 '22 at 06:08
  • I have sql server data tools I think, because Invoke-Sqlcmd command is working powershell that opened directly from windows. I added ss for compare. – nrllhcinar Feb 15 '22 at 06:30

0 Answers0