SSIS package not getting desired output - c#

i created an SSIS package and put in a server location and also a text file which is also in the same location where the .dtsx exist.Then i tried to call the SSIS package from my local machine using C# code.What the package is doing is taking data from the text file and storing in Database.I always get Failure message on package execution.Here is what i tried
Application app = new Application();
Package package = null;
try
{
string fileName = #"\\192.168.1.1\\Mypath\\file.txt";
package = app.LoadPackage(#"\\192.168.1.1\\Mypath\\Package.dtsx", null);
Variables vars = package.Variables;
vars["FileName"].Value = fileName;
DTSExecResult results = package.Execute();
}
catch (Exception ex)
{
throw ex;
}
finally
{
package.Dispose();
package = null;
}

Related

The file being use by another process when i add it programatically by SharpSvn

We are using SharpSvn to add SolidWorks files programatically to SVN tortoise.
When file is open in SolidWorks, i want to add it to SVN by code without closing file.
I used code below
var SvnResult = new SvnResult();
var FullPath = SvnHelper.FileCombine(FileName);
try
{
var SvnArg = new SvnAddArgs();
SvnArg.Force = true;
SvnArg.Depth = SvnDepth.Infinity;
//
SvnClient.Add(FullPath, SvnArg);
SvnResult.Message = "Success.";
SvnResult.Status = true;
//
return SvnResult;
}
catch (SvnException exc)
{
SvnResult.Message = exc.Message;
SvnResult.Status = false;
return SvnResult;
}
and i get error like this :
The process cannot access the file because it is being used by another process.
How can i add it to SVN without closing file?
Regards,
We solved the problem. At first we used TortoiseSvn.exe command lines to add and commit the file but when we used to send commit command, svn Dialog form was raised. For solving this problem I install “Command Line Client Tools” from the svn setup. By installing this option you can find svn.exe under svn path “C:\Program Files\TortoiseSVN\bin”.
I add this path to Environment Variables and then use svn command lines to add and commit while file is open.
public SvnResult CommitFiles_BySVNCmd(string filePath)
{
var fullPath = SvnHelper.FileCombine(filePath);
var svnResult = new SvnResult();
try
{
// svn add command
var status = GetStatus(fullPath);
//
if (status.LocalContentStatus == SvnStatus.NotVersioned)
{
var argumentsAdd = $#"add {fullPath}";
ProcessStart(argumentsAdd);
}
// svn commit command
var argumentsCommit = $#"commit -m Commited_Automatically {fullPath}";
ProcessStart(argumentsCommit);
svnResult.Message = "Success
svnResult.Status = true;
return svnResult;
}
catch (SvnException se)
{
svnResult.Message = se.Message;
svnResult.Status = false;
return svnResult;
}
}
private void ProcessStart(string arguments)
{
var processInfo = new ProcessStartInfo("svn", arguments);
processInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
Process.Start(processInfo);
}
Best Regards,

The specified network name is no longer available - C# Console Application

I am trying to read files from different server, using c# console application, but it gives error - "The specified network name is no longer available".
When I ping the server, i am getting a reply, but when I run the exe file of project that has code to access files from server it shows the mentioned error.
The path I am using is in this format: \\xxx.xxx.xx.x\EEE\EEE\FolderName
The code that access/read files:
public List<string> GetFiles()
{
List<string> filelist = null;
string fileFromPath = help.fileFromPath;
try
{
filelist = Directory.GetFiles(fileFromPath).ToList();
if (filelist.Count == 0)
{
log.Error("No file to be processed.");
}
}
catch (Exception ex)
{
log.Error(ex.Message);
}
return filelist;
}
Where help.fileFromPath has path value and it is stored in app.config
What could be the reason and how could it be fixed?

List the nuget package from nexus server

I want to get the nuget package list from some source
(https://nexus.sample.com) like that.When I try a below code
string void main(string args[])
{
Process commandProcess = new Process();
commandProcess.StartInfo.UseShellExecute = false;
commandProcess.StartInfo.FileName = #"C:\Nuget\nuget.exe"; // this is the path of curl where it is installed;
commandProcess.StartInfo.Arguments ="list -Verbose -AllVersions -Source http://nexus.sample.com/repository/nuget-hosted/";
commandProcess.StartInfo.CreateNoWindow = true;
commandProcess.StartInfo.RedirectStandardInput = true;
commandProcess.StartInfo.RedirectStandardOutput = true;
commandProcess.StartInfo.RedirectStandardError = true;
commandProcess.Start();
commandProcess.WaitForExit();
string output = commandProcess.StandardOutput.ReadToEnd();
}
the command console was not run.If I set StartInfo.RedirectStandardOutput= false.the command console was run.but I can't read the output value.Plese give any suggestion.
Instead of running the executable, why don't you just use NuGet.Core to list all packages ?
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("http://nexus.sample.com/repository/nuget-hosted");
foreach (IPackage p in repo.GetPackages())
{
Console.WriteLine(p.GetFullName());
}
For more infos : Play with Packages, programmatically!

c# html to Pdf Converter(Nreco)

i am using NReco html to pdf converter for my project.
It is giving me error for 3 days on server machine,it was working for months without any problem.Worse thing is , the project is working well on my local pc with same codes.I guess, the problem is related with some folder autorization or temp files which is already created on server pc.I have also deleted temp files under /user and windows/temp folders but still getting error:
the simple error message is : "The file exists"
Code:
public static byte[] ToPDF(this HttpContext context, string htmlContent )
{
string logFile = context.Request.PhysicalApplicationPath + "\\" + "log.txt";
try
{
var converter = new HtmlToPdfConverter();
converter.Margins = new PageMargins { Bottom = 20, Top = 18 };
var pdfBytes = converter.GeneratePdf(htmlContent); //THROW EXCEPTION ON THIS LINE
errorMsg = "Error Code:00x1";
return null;
}
catch (Exception exp)
{
errorMsg = "Error Code:00x2";
CreateErrorLog(context ,exp);
return null;
}
}
I have fixed it by updating NReco.PdfGenerator.dll to version to 1.1.11.0 , was using out-of date version(released 3 years ago) and error has gone.
Note: When i uninstall and install Nreco using Nuget Package manager , it is installed same old version , i don't know why so i had to download it from :
https://pdfgenerator.codeplex.com/
and manually remove old .dll from Project's references and add new NReco.PdfGenerator.dll

how to execute multiple ssis packages from c#

I have created 10 different packages and i want to execute them from c# coding. Can some one post some screen shots to achieve this.
I have tried this
Application app = new Application();
TraceService("loading system From File system");
//Create package Container to hold the package.
//And Load the Package Using the Application Object.
Package package = app.LoadPackage(#"C:\User\Kiran\Documents\Visual Studio 2012\Projects\WindowsServiceTest\WindowsServiceTest\Package1.dtsx", null);
TraceService("Execution Started");
DTSExecResult result = package.Execute();
// print the result
TraceService(result.ToString());
TraceService("Execution Completed");
Here i have to get the file name in run time not by hard coding
Following code will execute all packages from given folder.
var pkgLocation = #"C:\User\Kiran\Documents\Visual Studio 2012\Projects\WindowsServiceTest\WindowsServiceTest\";
foreach (var file in Directory.EnumerateFiles(pkgLocation, "*.dtsx"))
using (var pkg = new Application().LoadPackage(file, null))
{
var pkgResults = pkg.Execute();
Console.WriteLine("Package File Name:{0}, Result:{1}",file.ToString(), pkgResults.ToString());
}
The executing SSIS package from C# and VB is well documented in official site. This is my complete code in script task to execute multiple SSIS packages.
string packagesFolder = Dts.Variables["User::packagesFolder"].Value.ToString();
string rootFolder = Dts.Variables["User::rootFolder"].Value.ToString();
Package pkg;
Microsoft.SqlServer.Dts.Runtime.Application app;
DTSExecResult pkgResults;
foreach (var pkgLocation in Directory.EnumerateFiles(packagesFolder+"\\", "ValidateDataMigration-*.dtsx"))
{
try
{
app = new Microsoft.SqlServer.Dts.Runtime.Application();
pkg = app.LoadPackage(pkgLocation, null);
pkgResults = pkg.Execute();
File.AppendAllText(rootFolder + "\\DataValidationProgress.log", pkgLocation.ToString()+"=>"+ pkgResults.ToString()+ Environment.NewLine);
}
catch(Exception e)
{
File.AppendAllLines(rootFolder + "\\DataValidationErrors.log", new string[] { e.Message, e.StackTrace });
}
}

Categories