Shell Failure C#

Asked

Viewed 346 times

1

Friends, I ask for help to solve a small problem.

I am running SQL command through sqlcmd and Shell on C#, but the file is in a folder that contains "space", as follows.

Path: D: Sandboxes\CIA project\3-Development Scripts DDL DDL_T_DDW_CIA_PRODUTO_INDEXADOR.sql

When I run Shell the error is displayed: Win32exception: System cannot find specified file

Is there any way to make Shell understand the "space" in the Path?

Follow command that is running.

strScript = "sqlcmd -S server -i D: Sandboxes CIA Project 3-Development Scripts DDL DDL_T_DDW_CIA_PRODUTO_INDEXADOR.sql"

System.Diagnostics.Process.Start(strScript)

Thank you

Updating

Includes double quotes, but error remains.

sqlcmd -S servidor -U sa -P senha -i "D:\Pessoal\luiz.junior\Documents\Visual Studio 2012\Projects\AppNolock\AppNolock\bin\x86\Debug\Temp\Script.sql"

Error:System cannot find specified file

2 answers

2

Add quotes and escape them as follows:

strScript = "sqlcmd -S server -i \"D:\\Sandboxes\\Projeto CIA\\3-Desenvolvimento\\Scripts\\DDL\\DDL_T_DDW_CIA_PRODUTO_INDEXADOR.sql\""

Note that must escape the backslashes.

See here the result.

  • Omni, sorry for the delay, I got caught up with another project. I did exactly what was mentioned by you, but the problem continues!!!

0

I managed to solve the problem.

Instead of simply running the command line through Process.Start, I created a file. bat with the command line and this was executed by Process.Start.

            StringBuilder strScript = new StringBuilder();                
            var process = new System.Diagnostics.ProcessStartInfo();

            strScript.Append(String.Format("sqlcmd -S {0} -U sa -P mudar.123 -i \"{1}\"", cbServidor.Text, pathFile));
            Dados.GravarArquivo(PathTemp + @"\cmd.bat",strScript);
            FileInfo file = new FileInfo(PathTemp + @"\cmd.bat");

            process.WorkingDirectory = file.Directory.FullName;
            process.FileName = file.Name;
            process.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            System.Diagnostics.Process.Start(process).WaitForExit();
            System.Threading.Thread.Sleep(100);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.