?
Solved

Process Failure

Posted on 2005-03-23
4
Medium Priority
?
704 Views
Last Modified: 2012-06-21
I'm attempting to run the below SQL Server BCP command as a Process, but I'm getting the error, "Unhandled Exception: System.ComponentModel.Win32Exception: The system cannot find the file specified."  What could be causing this?  It runs fine using "Process.Start(Environment.GetEnvironmentVariable("COMSPEC")," /c bcp...", but I want it to wait before exiting; hence, the need for a Process.

Process p = new Process();
p.StartInfo.FileName = "bcp MyDB.dbo.MyTable in MyFile -m 1 -c -S MyServer -U MyUserId -P MyPassword";
p.Start();
p.WaitForExit();
0
Comment
Question by:arichexe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 13

Expert Comment

by:dungla
ID: 13618898
FileName property must point to a file name with full path and not including parameter
0
 

Author Comment

by:arichexe
ID: 13618938
How do I specify the parameters?
0
 
LVL 14

Accepted Solution

by:
Thandava Vallepalli earned 500 total points
ID: 13619096

try this one

      System.Diagnostics.Process proc = new System.Diagnostics.Process();
      proc.EnableRaisingEvents=false;
      proc.StartInfo.FileName = "bcp";
      proc.StartInfo.Arguments = "MyDB.dbo.MyTable in MyFile -m 1 -c -S MyServer -U MyUserId -P MyPassword";
      proc.Start();

itsvtk
0
 
LVL 14

Expert Comment

by:Thandava Vallepalli
ID: 13619103
Here is the sample program


================
using System;

class Demo
{
      public static void Main(string[] args)
      {
            if( args != null && args.Length > 0 )
            {
                  System.Diagnostics.Process proc = new System.Diagnostics.Process();
                  proc.EnableRaisingEvents=false;
                  proc.StartInfo.FileName = args[0];
                  proc.StartInfo.Arguments = (args.Length > 1 ? args[1] : "");
                  proc.Start();
                  proc.WaitForExit();
            }else
            {
                  Console.WriteLine( "Please provide 1 or 2 parameters \n Ex: process notepad (or) process calc" );
            }
      }
}
==============================

compile command: csc <filename.cs>
Execute command:  filename.exe  <processfilepath>  <arguments to the process>

itsvtk
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question