Run SSIS package in asp.net using powershell - asp.net

Can anyone tell me how to run SSIS package with powershell on the server in asp.net. Please note i need to specify config file path also.
var processStartInfo = new ProcessStartInfo
{
Arguments = "dtexec /F " + "\"" + pkgPath + packageName +"\"",
FileName = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
};
Process process = Process.Start(processStartInfo);
How to specify the config file path in the above code.

Related

Execute .jar file in .net core on Openshift container platform

net core application which internally calls a java (.jar) file using .net Process class. I have used cmd.exe to run .jar file along with parameters. I have deployed this application on Openshift Container Platform. But as openshift is running on Linux, so cmd.exe is not available.
Below is code in .net core to execute jar file.
Process cmd = new Process();
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.WorkingDirectory = Common.JarWorkingDir;
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.Arguments = "/K java -jar " + string.Format("{0} {1}", '"' + Common.JarFilePath + '"', '"' + sourceCodePath + '"');
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.RedirectStandardInput = true;
cmd.Start();
cmd.StandardInput.WriteLine("exit");
cmd.StandardInput.Flush();
cmd.WaitForExit();
So Jar file is unable to execute. Any alternative to execute this jar with .net on OpenShift. Please help.
OpenShift is essentially Kubernetes running Linux containers. In other words, your code should act as if it is running on Linux.
Instead of cmd.exe, use bash (or, sh, or really, whatever shell is pre-installed in your container):
Process cmd = new Process();
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.WorkingDirectory = Common.JarWorkingDir;
cmd.StartInfo.FileName = "bash";
cmd.StartInfo.Arguments = "-c 'java -jar " + string.Format("{0} {1}", '"' + Common.JarFilePath + '"', '"' + sourceCodePath + '"'');
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.RedirectStandardInput = true;
cmd.Start();
cmd.StandardInput.WriteLine("exit");
cmd.StandardInput.Flush();
cmd.WaitForExit();
You can maybe even remove some of the lines. CreateNoWindow, for example, is not required because .NET Core does not create windows on Linux at all.
If you have no shell expressions, perhaps you can even get things to be simpler and simplify from this:
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.FileName = "bash";
cmd.StartInfo.Arguments = "-c 'java -jar " + string.Format("{0} {1}", '"' + Common.JarFilePath + '"', '"' + sourceCodePath + '"'');
to something like this:
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.FileName = "java";
cmd.StartInfo.Arguments = $"-jar \"{Common.JarFilePath}\" \"{sourceCodePath}\"";
Oh, and watch out for the quoting in your Arguments variable. If you wrap the entire command after -c with single quotes, you should be fine, but if you are doing something trickier - if Common.JarFilePath isn't a simple file name - it may not work so well. Definitely test and tweak that. Maybe consider EscapeAndConcatenate.

Why i get error in dtexec command in asp.net?

I'm new in asp.net,and want to write code to run sql server dtexec for that purpose write this code:
System.Diagnostics.Process si = new System.Diagnostics.Process();
si.StartInfo.WorkingDirectory = #"c:\";
si.StartInfo.UseShellExecute = false;
si.StartInfo.FileName = "cmd.exe";
si.StartInfo.Arguments = "/C dtexec / f E:/Package.dtsx / set /package.variables[FilePath].Value; e:\testFile.txt";
si.StartInfo.CreateNoWindow = true;
si.StartInfo.RedirectStandardInput = true;
si.StartInfo.RedirectStandardOutput = true;
si.StartInfo.RedirectStandardError = true;
si.Start();
string output = si.StandardOutput.ReadToEnd();
si.Close();
but when i run that code,get this error:
Microsoft (R) SQL Server Execute Package Utility Version 12.0.2000.8 for 64-bit Copyright (C) Microsoft Corporation. All rights reserved. Option "/" is not valid.
How can i solve that problem?thanks all.
You should remove whitespaces from this line, like that:
si.StartInfo.Arguments = "/C dtexec /f E:\\Package.dtsx /set \\package.variables[FilePath].Value;e:\\testFile.txt"
You should also be able to run your command in cmd.exe:
dtexec /f e:\package.dtsx /set \package.variables[FilePath].Value;e:\testFile.txt
Unless it will work in cmd, it won't work also from your code.

PowerShell script not working on server

I have a simple PowerShell script in which I try to write some log data.
The script that's not working:
Add-Content -Path C:\temp\logg.txt -Value $file.FullName
This line I placed in the middle of the script and I never get any text in the logg.txt. The Script executes fine except this, it compiles some files to a zip file.
This is on a Windows server.
If I, however, run the same script on my local machine, Win7, it does work!?
So I think it must be something with the server but I can't figure it out. Am using -ExecutionPolicy Bypass when I run the script.
EDIT: more info.
The script is called from an ASP.NET webpage:
Process.Start("Powershell.exe", "-ExecutionPolicy Bypass -Command ""& {" & destinationFolderRoot.Replace("\\", "\") & "\scriptParameters.ps1}""")
BaseZipScript:
function New-Zip
{
param([string]$zipfilename)
Set-Content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
}
function Add-Zip
{
param([string]$zipfilename)
if(-not (Test-Path($zipfilename)))
{
Set-Content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
}
$shellApplication = New-Object -COM Shell.Application
$zipPackage = $shellApplication.NameSpace($zipfilename)
foreach($file in $input)
{
$zipPackage.CopyHere($file.FullName)
Add-Content -Path "C:\temp\logg.txt" -Value $file.FullName
Start-Sleep -Milliseconds 750
}
}
scriptParameters1:
. "C:\temp\multiDownload\baseZipScript.ps1"
New-Zip c:\temp\multiDownload\user379\2016-09-15_14.39\files_2016-09-15_14.39.zip
dir c:\temp\multiDownload\user379\2016-09-15_14.39\tempCopy\*.* -Recurse |
Add-Zip c:\temp\multiDownload\user379\2016-09-15_14.39\files_2016-09-15_14.39.zip
Start-sleep -milliseconds 250
exit
As I said earlier the script works on local machine and also on the server, e.g. the files are being zipped, except that on the server nothing is logged in logg.txt.
Though the logg.txt works and exists on the server because the webpage also log some info there and that is being written.
Update:
As the comments guessed it was as simple as write access to the file. Though, it is kind of wierd because all files are created from the webservice if they doesn't exists? Any how, it works now. Thx! : )

How can I download a basic authentication-protected file in a Chocolatey install script?

The Install-ChocolateyZipPackage commandlet does not seem to support basic authentication when it comes to downloading files, i.e. via an URL such as https://user:password#example.com/file.zip. How can I work around this in my Chocolatey install script, i.e. download the file in question (e.g. https://user:password#example.com/file.zip) before I install it via Install-ChocolateyZipPackage?
Thomas put up a good answer in the group forum - https://groups.google.com/forum/#!msg/chocolatey/e4lcPIrLhis/vfSUVe0SZcIJ
As far as I know, authentication is not supported. But you could
specify wget as dependency and use that to download the file.
I use it in one of my packages for authentication and it works fine:
https://chocolatey.org/packages/rukerneltool#files (look at chocolateyInstall.ps1)
On Linux, wget would be the first choice to handle such things in a
Bash script.
But if the software you want to make a package of is Open Source, you
could integrate it directly into the package. That makes it easier.
Code for this is (in case it is later changed:
$webClient = New-Object System.Net.WebClient
$webClient.Credentials = New-Object System.Net.Networkcredential($username, $password)
Write-Output $('Downloading' + $url + '…')
$webClient.DownloadFile($url, $zipFilePath)
I use a similar way without wget, to fetch artifacts from our company's buildserver
$packageName = 'mycompanypackage'
$installerType = 'exe'
$username = 'chocolatey'
$password = '************'
$url = 'http://bamboo.mycompany.com/browse/DP-RS/latestSuccessful/artifact/JOB1/Setup/setup.exe'
$downloadFile = $url.Substring($url.LastIndexOf("/") + 1)
$url = $url+'?os_authType=basic'
$url64 = $url
$silentArgs = '/VERYSILENT /NORESTART /SUPPRESSMSGBOXES'
if (Test-Path "$downloadFile") {Remove-Item "$downloadFile"}
$webclient = new-object System.Net.WebClient
$credCache = new-object System.Net.CredentialCache
$creds = new-object System.Net.NetworkCredential($username, $password)
$credCache.Add($url, "Basic", $creds)
$webclient.Credentials = $credCache
$webclient.DownloadFile($url, $downloadFile)
Install-ChocolateyInstallPackage "$packageName" "$installerType" "$silentArgs" "$downloadFile"

Writing Output Files using CreateJavaObject in Peoplesoft

I am trying to write an application engine program which would generate an output file. My goal is to write this file by using the PeopleSoft function 'CreateJavaObject'. I tried this:
Local string &msg;
Local JavaObject &jFile, &writeFile;
&msg = "Hello World!";
&jFile = CreateJavaObject("java.IO.File", "c:\temp\log.txt");
&writeFile = CreateJavaObject("java.IO.BufferedWriter", &jFile);
&writeFile.writeFile(&msg);
When I run the application engine program, the program abends and the error is at the object java.IO.BufferedWriter which says incorrect argument passed.
Is there any way in peoplesoft where File I/O can be handled in using java functions.
I have fixed the issue. Here is the code
Local JavaObject &jFile;
Local JavaObject &msg;
&msg = CreateJavaObject("java.lang.String", "Hello World!");
Local JavaObject &buf = &msg.getBytes();
Local number &byteCount = &buf.length;
&jFile = CreateJavaObject("java.io.FileOutputStream", "C:\Temp\java.txt", True);
&jFile.write(&buf, 0, &byteCount);
&jFile.close();

Resources