I'm new in generating SSIS packages programmatically and I have an issue in one of the components that I'm generating.
I'm generating a Script Task programmatically with the code below:
private void EditScriptTask(ref ScriptTask pScriptTask, List<VariablesSsis> variablesSsis)
{
pScriptTask.ScriptProjectName = ScriptTaskProjectName;
// Set the script language - "CSharp"
pScriptTask.ScriptLanguage = VSTAScriptLanguages.GetDisplayName("CSharp");
// Set variables to be used in the script task code (read and write variables)
pScriptTask.ReadWriteVariables = ReadVariableScriptString(variablesSsis);
// Create a new project from the template located in the default path - script task associated project
pScriptTask.ScriptingEngine.VstaHelper.LoadNewProject(pScriptTask.ProjectTemplatePath, null, ScriptTaskProjectName);
//Initialize the designer project, add a new code file, and build
pScriptTask.ScriptingEngine.VstaHelper.Initalize("", true);
pScriptTask.ScriptingEngine.VstaHelper.AddFileToProject("ScriptMain.cs", "file contents");
pScriptTask.ScriptingEngine.VstaHelper.Build("");
// Persist the VSTA project + binary to the task
if (!pScriptTask.ScriptingEngine.SaveProjectToStorage())
{
throw new ArgumentNullException("Save failed");
}
// Replace ScriptMain contents
var contents = GetScriptMainContent();
pScriptTask.ScriptStorage.ScriptFiles["ScriptMain.cs"] = new VSTAScriptProjectStorage.VSTAScriptFile(VSTAScriptProjectStorage.Encoding.UTF8, contents);
// Reload the script project, build and save
pScriptTask.ScriptingEngine.LoadProjectFromStorage();
pScriptTask.ScriptingEngine.VstaHelper.Build("");
//Cleanup
pScriptTask.ScriptingEngine.DisposeVstaHelper();
}
private string GetScriptMainContent()
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "Va.Api.MyServiceSSIS.Infrastructure.Scripts.ScriptMain.txt";
Stream stream = assembly.GetManifestResourceStream(resourceName);
StreamReader reader = new StreamReader(stream);
return reader.ReadToEnd();
}
The package and the Script Task in it are generated with no issues but when I try to run the package in Visual Studio that's when I get the issue:
for the Script Task it seems that it runs the code inside (giving execution finished with success) but actually it doesn't.
To solve this problem I have to open the script task editor, click on "Edit Script" that opens Visual Studio and the code to be run by the Script Task, then close VS and click OK in the Script Task editor.
If I do the above the Script Task runs the code correctly and I have no problems.
I'm using SQL Server 2014, VS 2013 (but when I open the script of the Script Task he opens the VS 2012)
Anyone had already a similar problem? Or can give me a tip?
I think it's maybe compilation problem, but theoretical in my code I'm already doing it by calling the Build method or not? (if I look at the xml code it seems like it has already hte binary code has already been built)
Thanks in advance.
Related
I have downloaded and attached the FixedVersionRuntime.88.0.705.81.x64 for WebView2 and attached it to my project.
Using the following it should load the necessary page but when loading the WebView is not crashing but no page is loaded:
public async Task InitializeAsync()
{
string installPath = #"C:\Program Files (x86)\WebView2Runtime\Microsoft.WebView2.FixedVersionRuntime.88.0.705.81.x64\";
var webView2Environment = await CoreWebView2Environment.CreateAsync(installPath);
await browserControl.EnsureCoreWebView2Async(webView2Environment);
}
I am then setting the source after this:
await InitializeAsync();
me.Source = new Uri(((MainViewModel)this.DataContext).Config.DefaultURL);
When using the evergreen installer it worked fine but when moving to the fixed version it seems to not load correctly when deployed.
I've tested the following, which seems to work:
Download WebView2 Fixed Version
Example
Given:
WebView2 Fixed Version: Microsoft.WebView2.FixedVersionRuntime.88.0.705.81.x86.cab
Project folder: C:\Projects\WpfTestFixedVersion
Output folder: C:\Projects\WpfTestFixedVersion\WpfTestFixedVersion\bin\Debug
Project compiled using:
Configuration: Debug
Platform: Any CPU (Prefer 32-bit)
Extract files from .cab
Open a cmd window
cmd window
C:\Users\Test\Downloads> expand Microsoft.WebView2.FixedVersionRuntime.88.0.705.81.x86.cab -F:* "C:\Projects\WpfTestFixedVersion\WpfTestFixedVersion\bin\Debug"
Note: When using expand in the above command, the destination folder must already exist and the name must not end with '\'.
C:\Projects\WpfTestFixedVersion\WpfTestFixedVersion\bin\Debug
C:\Projects\WpfTestFixedVersion\WpfTestFixedVersion\bin\Debug\Microsoft.WebView2.FixedVersionRuntime.88.0.705.81.x86
Option 1:
InitializeAsync
public async Task InitializeAsync()
{
string installPath = #".\Microsoft.WebView2.FixedVersionRuntime.88.0.705.81.x86";
var webView2Environment = await CoreWebView2Environment.CreateAsync(installPath);
await browserControl.EnsureCoreWebView2Async(webView2Environment);
}
Option 2:
Note: This option allows one to specify the userDataFolder. If it's not specified, it uses the user's temp folder as the location for the userDataFolder.
InitializeAsync
public async Task InitializeAsync(WebView2 wv, string webCacheDir = "")
{
CoreWebView2EnvironmentOptions options = null;
string tempWebCacheDir = string.Empty;
CoreWebView2Environment webView2Environment = null;
//set value
tempWebCacheDir = webCacheDir;
if (String.IsNullOrEmpty(tempWebCacheDir))
{
//get fully-qualified path to user's temp folder
tempWebCacheDir = System.IO.Path.GetTempPath();
tempWebCacheDir = System.IO.Path.Combine(tempWebCacheDir, System.Guid.NewGuid().ToString("N"));
}
//use with WebView2 FixedVersionRuntime
webView2Environment = await CoreWebView2Environment.CreateAsync(#".\Microsoft.WebView2.FixedVersionRuntime.88.0.705.81.x86", tempWebCacheDir, options);
//webView2Environment = await CoreWebView2Environment.CreateAsync(#"C:\Program Files (x86)\Microsoft\Edge Dev\Application\90.0.810.1", tempWebCacheDir, options);
//webView2Environment = await CoreWebView2Environment.CreateAsync(null, tempWebCacheDir, options);
//wait for CoreWebView2 initialization
await wv.EnsureCoreWebView2Async(webView2Environment);
}
The answer by #user9938 is comprehensive. But please also note that the version of "WebView2Loader.dll" which is in use is very crucial. I had almost the same problem with "Microsoft.WebView2.FixedVersionRuntime.101.0.1210.39.x64" when I tried to use the WebView2 component in the MMC Snap-Ins with types of "HTMLView" or "FormView".
I just copied the abovementioned dll file (version 1.0.1248.0, size=157640 bytes) in a proper path that was accessible for the project (you could just put it beside your project output files first to test it) and then WebView2 browser started to function as expected. Microsoft error messages sometimes (at least in my case) was a little bit misleading and did not convey enough and to the point information.
I received "BadImageFormatException" that normally occurs when you mix platform targets (for example using a dll file compiled in X64 in an application that targeted for x86 or vice versa) or mix native code and .NET but that was not my problem at all. I hope this help one who may stuck in.
I'm developing asp.net core application + IronPython.
But I've faced with the debugging issue...
So for example I have following code:
Dictionary<string, object> options = new Dictionary<string, object>();
options["Debug"] = true;
ScriptEngine engine = Python.CreateEngine(options);
// output redirect
var eIO = engine.Runtime.IO;
var errors = new MemoryStream();
eIO.SetErrorOutput(errors, Encoding.Default);
var result = new MemoryStream();
eIO.SetOutput(result, Encoding.Default);
// execute script
ScriptScope scope = engine.CreateScope();
scope.SetVariable("testGlobalVar", 10);
engine.ExecuteFile(ScriptPath, scope);
in python file
some = "Test"
print(Test)
print("We have ->", testGlobalVar)
It works fine, but I don't know how to set breakpoint in python file and debug it step by step in Visual Studio, Pycharm(whatever), when running it via C#.
I found this question but it's almost completely useless. I'm setting breakpoint in python file and nothing happens.
Since it works well without debug mode as you mentioned. I think the reason for why the breakpoint won't be hit in debug mode is debugger can't find it.
Please Go=>Debug=>Options=>Uncheck Enable Just My Code to check if it helps.
Note:
Set the .net core app as startup project
If the uncheck Enable Just My Code not help, I suggest you go tools->Import/Export Settings->reset all settings, then uncheck the Enable Just My Code again.
After that, the breakpoint can be hit like below:
In addition: I use the .net console app to reproduce and test, but I think it has similar behavior like web-app. Any update feel free to contact me :)
I'm just dummy in using SSIS&*.dtsx files from C#. Now I have WindowsForms project and OnClick handler with this code:
.....
string pkgLocation;
Package pkg;
Microsoft.SqlServer.Dts.Runtime.Application app;
DTSExecResult pkgResults;
DTSEvents dtsEvents=new DTSEvents();
pkgLocation = System.Windows.Forms.Application.StartupPath+ #"\" + #"3StreamsImport.dtsx";
app = new Microsoft.SqlServer.Dts.Runtime.Application();
app.PackagePassword = "abudfv";
app.EnableDump = true;
app.DumpOnAnyError = true;
pkg = app.LoadPackage(pkgLocation, dtsEvents,true);
try {
pkgResults = pkg.Execute(null,null,dtsEvents,null,null);
}catch(System.Runtime.InteropServices.COMException ex) {
Console.WriteLine(ex.StackTrace);
}
.......
"3Streamsimport.dtsx" file was created with SqlServer management studio for SqlServer 2016 and is working fine from standard Еxecute Package Utility. Loading package in my code passes fine too. But executing fails allways! dtsEvents is instanceof object that implements all from IDTSEvents interface.
Dear ALL, who can help with definitions of ways to solve the problem?
It's been a while since I tried, so I don't know if later versions have improved anything, but I was never able to get an SSIS package to execute from C# the way you are trying to do.
What I eventually did was create a job that executed the package, and used C# to start the job. It worked fine.
Solved! All C# code is fine. As addition I'm implemented IDTSLogging. After changing "exectute" call to
pkgResults = pkg.Execute(null,null,dtsEvents,new DTSLogging(),null);
all events are firing smoothly. I don'nt know/ why, but it is working.
Now about DTSX- file: It was my mistake in project and the proper copy was simply in other place! :-(
Sorry :-(
I am attempting to create a copy of an existing dtsx file so I can change a few variables based on input from the user. I am able to make a copy of the file, look at the variables, and set the variables to the correct input. However, when I go to look at the file in Visual Studio I get a few errors.
Microsoft Visual Studio is unable to load this document: The package failed to load to to error 0xC0010014 "One or more error occurred. There should be more specific errors preceding this one that explains the details of the errors. This message is used as a return value from functions that encounter errors". This occurs when CPackage::LoadFromXML fails.
The errors contained in the error list:
Error 3 Error loading test.dtsx: Error loading value "<DTS:Property xmlns:DTS="www.microsoft.com/SqlServer/Dts" DTS:Name="PackageFormatVersion">6</DTS:Property>" from node "DTS:Property". E:\test.dtsx 1 1
The version number in the package is not valid. The version number cannot be greater than current version number.
I looked into these errors and I saw potential issues with the server year and visual studio year. Both of these are the 2008 version.
My code:
string pkgPath = #"\\server\TestFolder\test.dtsx"
app = new Microsoft.SqlServer.Dts.Runtime.Application();
pkg = app.LoadPackage(pkgPath, null);
Console.WriteLine(pkg.Variables["filename"].Value.ToString());
pkg.Variables["filename"].Value = "testFile";
Console.WriteLine(pkg.Variables["filename"].Value.ToString());
app.SaveToXml(pkgPath, pkg, null);
If I open the file I am using to make a copy of in Visual Studio, it works no problem -- something strange is happening when I do app.SaveToXML();
Any ideas or suggestion would be wonderful.
To run this as a process from DTEXEC, it would look something like below. Please check out these two links for further details about ProcessStartInfo and how to use /SET so you can add that to your argument. Test this from the command line first because the syntax can be finicky.
https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo(v=vs.110).aspx
https://technet.microsoft.com/en-us/library/ms162810(v=sql.105).aspx
Using System.Diagnostics;
string args = #"/F'c:\MyPackage.dtsx' /SET'\package.variables[myvariable].Value;myvalue'";
ProcessStartInfo executePackage = new ProcessStartInfo("dtexec", args);
executePackage.UseShellExecute = false;
executePackage.RedirectStandardError = true;
executePackage.RedirectStandardOutput = true;
executePackage.CreateNoWindow = true;
StringBuilder output = new StringBuilder();
Process executing = Process.Start(executePackage);
while(!executing.StandardOutput.EndOfStream)
{
output.AppendLine(executing.StandardOutput.ReadLine();
}
executing.WaitForExit():
We have the following code in wizard to add existing project to a new solution:
//generating files
if (dte.Solution.Projects.Count < 1) // Solution is empty or doesn't exist
{
dte.Solution.Create(oneFolderHigher(Params.OutputDir, solutionName),
solutionFileName(solutionName));
}
// adding created project to solution
dte.Solution.AddFromFile(Path.Combine(Params.ProjectRootFolder,
Params.ProjectName + ".csproj"));
It works just fine under MS Visual Studio 2010, but fails under 2012 (I experimented with second parameter):
System.Runtime.InteropServices.COMException (0x80004004): Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))
at EnvDTE.SolutionClass.AddFromFile(String FileName, Boolean Exclusive)
at Wizard.Generator.NewProjectGenerator.Generate(Action`1 logMessage)
at Wizard.Forms.WizardForm.Finish()
After this error I'm adding the new project to the solution manually and everything works OK. But we can not just say, "Sorry, we can not add newly generated project for you so please add it by yourself."
MSDN proposes:
You can use the LaunchWizard method rather than AddFromFile to execute a wizard if you want to suppress its UI during execution. LaunchWizard has a parameter that allows you to disable the UI.
But this method requires some wizard file, so it can not be a solution.
Could someone help?
Wizard is running from "New -> Project" menu.
Here the workaround for the issue (proposed by my boss):
Before adding the project to solution, project file should be converted to
VS2012 format.
But code is little ugly:
using (StreamReader sr = new StreamReader(newFile))
using (StreamWriter sw = new StreamWriter(projectFile, false, Encoding.UTF8))
{
while (sr.Peek() >= 0)
{
string s = sr.ReadLine();
if (s.Contains("<Project ToolsVersion=\"4.0\""))
{
s = s + Environment.NewLine + importProject;
}
... and so on
Maybe someone knows the way to do it awesome? I mean converting. I'll let the question to be unanswered some time. Waiting for your comments.