Calling BCP from .net on Windows 2012
-
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()
-
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()
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