Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Calling BCP from .net on Windows 2012

Calling BCP from .net on Windows 2012

Scheduled Pinned Locked Moved Visual Basic
csharpsysadminsecurityhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    byka
    wrote on last edited by
    #1

    I am running into the issue:Access Denied when calling bcp from Windows 2012 server. Any idea what it could be? Running in elevated mode.

    Dim ps As New System.Diagnostics.Process
    ps.StartInfo.UseShellExecute = False
    ps.StartInfo.Domain = Domain
    ps.StartInfo.UserName = UserName
    Dim pword As New System.Security.SecureString()
    For Each c As Char In Password
    pword.AppendChar(c)
    Next
    ps.StartInfo.Password = pword
    ps.StartInfo.LoadUserProfile = False
    ps.StartInfo.WorkingDirectory = "E:\"
    ps.StartInfo.FileName = "cmd.exe"
    'Win2012 run as admin (elevated mode)
    ps.StartInfo.Verb = "runas"
    ps.StartInfo.Arguments = " bcp " + DbTable + " in " + SourceFile + " -m " + MaxErrors + " -f " & FMTFile & " -e " & ErrorFile & " -o " & LogFile & " -S " & ServerName & " -T"

             ps.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
            ps.Start()
    
            ps.WaitForExit()
    
    D 1 Reply Last reply
    0
    • B byka

      I am running into the issue:Access Denied when calling bcp from Windows 2012 server. Any idea what it could be? Running in elevated mode.

      Dim ps As New System.Diagnostics.Process
      ps.StartInfo.UseShellExecute = False
      ps.StartInfo.Domain = Domain
      ps.StartInfo.UserName = UserName
      Dim pword As New System.Security.SecureString()
      For Each c As Char In Password
      pword.AppendChar(c)
      Next
      ps.StartInfo.Password = pword
      ps.StartInfo.LoadUserProfile = False
      ps.StartInfo.WorkingDirectory = "E:\"
      ps.StartInfo.FileName = "cmd.exe"
      'Win2012 run as admin (elevated mode)
      ps.StartInfo.Verb = "runas"
      ps.StartInfo.Arguments = " bcp " + DbTable + " in " + SourceFile + " -m " + MaxErrors + " -f " & FMTFile & " -e " & ErrorFile & " -o " & LogFile & " -S " & ServerName & " -T"

               ps.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
              ps.Start()
      
              ps.WaitForExit()
      
      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      First, you don't need the RunAs verb line at all. Next, the command line you build is this:

      cmd bcp something in something -m ...
      

      That command line is wrong for CMD. Next, you don't even run CMD. Your Filename line should be "bcp". The Arguments should be almost everything you already have in existing statement.

      ps.StartInfo.FileName = "bcp"
      ps.StartInfo.Arguments = String.Format("{0} in {1} -m {2} -f {3}...", DbTable, SourceFile, MaxErrors, FMTFile, ...
      ps.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
      ps.Start()
      ps.WiatForExit()
      

      On top of everything else, in order for the Hidden window option to work you have to change the UseShellExecute property to True.

      A guide to posting questions on CodeProject

      Click this: Asking questions is a skill. Seriously, do it.
      Dave Kreskowiak

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups