I get this error message when trying to run a SSIS package in C#. The error is:
Error in Microsoft.SqlServer.Dts.Runtime.TaskHost/SSIS.Pipeline : To run a SSIS
package outside of SQL Server Data Tools you must install Standard Edition of Integration Services or higher.
I checked the development machine and the server, and both have the SSDT installed. The target SQL Server is 2012, and I ran a report to check the edition of Integration Services that is running and it is the Standard Edition (11.3.6020.0). I noticed that the error occurs when it runs the data flow tasks that implement some derived column transformations. Any ideas on how to fix this issue? Thanks for your help!
Here is my C# code:
class MyEventListener : DefaultEvents
{
public override bool OnError(DtsObject source, int errorCode, string subComponent,
string description, string helpFile, int helpContext, string idofInterfaceWithError)
{
// Add application-specific diagnostics here.
Console.WriteLine("Error in {0}/{1} : {2}", source, subComponent, description);
return false;
}
}
class Program
{
static void Main(string[] args)
{
GetExtractsData();
}
static void GetExtractsData()
{
string pkgLocation;
Package pkg;
Application app;
DTSExecResult pkgResults;
MyEventListener eventListener = new MyEventListener();
pkgLocation = #"C:\Package.dtsx";
app = new Application();
pkg = app.LoadPackage(pkgLocation, null);
pkg.EnableConfigurations = true;
Configuration config = pkg.Configurations.Add();
config.ConfigurationType = DTSConfigurationType.ConfigFile;
config.ConfigurationString=#"C:\Extracts_Config.dtsConfig";
pkgResults = pkg.Execute(null, null, eventListener, null, null);
Console.WriteLine(pkgResults.ToString());
Console.WriteLine("The Extracts completed downloading at: " + DateTime.Now.ToString());
}
Related
I created a SSIS script task which reads data from excel sheets and saves it into different tables in SQL Server DB. When I execute the SSIS package inside Visual Studio SSDT it works fine.
When I am trying to execute my SSIS package from C# .NET code I get the following error.
Error in Microsoft.SqlServer.Dts.Runtime.TaskHost/Script Task : There was an exception while loading Script
Task from XML: System.Exception: The Script Task "ST_71d9425916264171ab93a0d340aad54d" uses version 14.0 script
that is not supported in this release of Integration Services. To run the package, use the Script task to create
a new VSTA script. In most cases, scripts are converted automatically to use a supported version,when you open a
SQL Server Integration Services packages in %SQL_Product_Short_Name% Integrtion Services.
I tried to change the deployment version by changing the TargetServerVersion to SQL server 2016 but I still get the same error.
Here is my code to execute the package.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Microsoft.SqlServer.Dts.Runtime;
namespace Execute_DriverImpact
{
class MyEventListener : DefaultEvents
{
public override bool OnError(DtsObject source, int errorCode, string subComponent,
string description, string helpFile, int helpContext, string idofInterfaceWithError)
{
// Add application-specific diagnostics here.
Console.WriteLine("Error in {0}/{1} : {2}", source, subComponent, description);
return false;
}
}
class Program
{
static void Main(string[] args)
{
// The code provided will print ‘Hello World’ to the console.
// Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.
//Console.WriteLine("Hello World!");
//Console.ReadKey();
//ExecuteSSIS exec = new ExecuteSSIS();
//exec.ExePackage();
//ExecuteSSIS2 exec = new ExecuteSSIS2();
//exec.ExePackage2();
string pkgLocation;
Package pkg;
Application app;
DTSExecResult pkgResults;
MyEventListener eventListener = new MyEventListener();
pkgLocation =
#"D:\Driver_Impact\Driver_Impact\Package.dtsx";
app = new Application();
pkg = app.LoadPackage(pkgLocation, eventListener);
pkgResults = pkg.Execute(null, null, eventListener, null, null);
Console.WriteLine(pkgResults.ToString());
Console.ReadKey();
}
}
}
Tech Stack
Visual Studio 2017 with SSDT
SQL server 2016
I am following a tutorial, in one step it opens "VS2012 arm cross tools command prompt" and executes
xsd file.xsd /classes
I can't find "VS2012 arm cross tools command prompt" on my computer (my guess it's because I'm using VS2019) so I open the "Developer command prompt for VS 2019" instead, but when I run the command, I get an error:
"xsd" is not recognized as an internal or external command, program or executable batch file
Can someone tell me how I can create a class from an xsd file in VS 2019? Thank you for your time.
Once you have installed the Windows SDK. The following could be of help to you...it is .NET Core. Browse to the xsd.exe and add a reference to it in VS 2019.
class Program
{
static void Main(string[] args)
{
var rgs = new string[]
{
#"PathToYourDLL\My.dll",
"/type:ClassNameToGen"
};
AppDomain.CurrentDomain.FirstChanceException += (s, e) =>
{
string error = e.Exception.ToString();
var typeLoadException = e.Exception as ReflectionTypeLoadException;
if (typeLoadException != null)
{
foreach (var exception in typeLoadException.LoaderExceptions)
{
error += Environment.NewLine + Environment.NewLine + exception.ToString();
}
}
Console.WriteLine(error);
};
XsdTool.Xsd.Main(rgs);
Console.ReadLine();
}
}
I have a .NET Core 2.2 API running on IIS on a Windows Server 2012 R2 Datacenter machine. It uses the DLLs from Nuget package Microsoft.SharePointOnline.CSOM. But it throws exception One or more errors occurred. (The process has no package identity. (Exception from HRESULT: 0x80073D54)) when calling method ClientContext.ExecuteQueryAsync().
I have followed the following guide: https://rajujoseph.com/getting-net-core-and-sharepoint-csom-play-nice/ . I have tried two solutions. The first was creating a .NET Core Console solution that calls the DLL containing the SharePoint CSOM code. Then I tried calling the DLL from a .NET Core 2.2 API running on IIS on a Windows Server 2012 R2 Datacenter machine. But both solutions throw the same exception as mentioned above One or more errors occurred. (The process has no package identity. (Exception from HRESULT: 0x80073D54)).
The SharePointHelper.dll code:
using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.Text;
namespace SharePointHelper
{
public class SharePointHelper
{
public SharePointHelper() { }
public void WriteFilesAndFolders(string siteUrl, string listName, string username, string password)
{
using (var context = new ClientContext(siteUrl))
{
context.Credentials = new SharePointOnlineCredentials(username, password);
var folder = context.Web.GetFolderByServerRelativeUrl(listName);
var subFolders = folder.Folders;
var files = folder.Files;
context.Load(folder);
context.Load(subFolders);
context.Load(files);
if (context.HasPendingRequest)
context.ExecuteQueryAsync().Wait();
var subFolderEnumorator = subFolders.GetEnumerator();
var filesEnumerator = files.GetEnumerator();
PrintValues(subFolderEnumorator);
PrintValues(filesEnumerator);
}
}
private void PrintValues(IEnumerator<Folder> enumerator)
{
while (enumerator.MoveNext())
Console.WriteLine(enumerator.Current.Name);
}
private void PrintValues(IEnumerator<File> enumerator)
{
while (enumerator.MoveNext())
Console.WriteLine(enumerator.Current.Name);
}
}
}
The .NET Core 2.2 service code calling the method in the SharePointHelper.dll:
public void SharePointTest()
{
string siteUrl = #"https://somecompany.sharepoint.com/sites/Test";
string listName = "Documents";
string username = "myemail#somecompany.com";
string password = "mypassword";
var sharePointHelper = new SharePointHelper.SharePointHelper();
sharePointHelper.WriteFilesAndFolders(siteUrl, listName, username, password);
}
I expect the SharePointHelper.dll to connect and get a response from SharePoint. But exception One or more errors occurred. (The process has no package identity. (Exception from HRESULT: 0x80073D54)) is thrown.
You can solve this problem to use SharePoint with .NET Core by simply installing the TTCUE.NetCore.SharepointOnline.CSOM Nuget package. No reason to follow the linked guide unless you want to understand how to do the workaround in depth.
I have a windows service that is written in .NET, and i used probing feature in order to load dll's to this windows service. However, when i open command prompt and try to install windows service using installutil.exe, i got an error such as: "System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Aborting installation for",
On the other hand, when i move dll's in the same folder with windows service and repeat the installation procedure, windows service is installed successfully.
Do you have any ideas or suggestions about this problem?, is there a probing problem in windows service installation of .NET?
I face the same problem in my project, in my windows service project i have the following app.config section:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="SDK" />
</assemblyBinding>
</runtime>
if i executed the service as a console all is well, but when i try to install it the installutil failed and i got the same exception, so my solution is made the service installed itself by a command line: like so:
cmd: hotspotcenter -i <service_name="service name">
// service_name i made it optional
the Installer class helper:
internal static class BasicServiceInstaller
{
public static void Install(string serviceName)
{
CreateInstaller(serviceName).Install(new Hashtable());
}
public static void Uninstall(string serviceName)
{
CreateInstaller(serviceName).Uninstall(null);
}
private static Installer CreateInstaller(string serviceName)
{
var installer = new TransactedInstaller();
installer.Installers.Add(new ServiceInstaller
{
ServiceName = serviceName,
DisplayName = serviceName,
StartType = ServiceStartMode.Manual
});
installer.Installers.Add(new ServiceProcessInstaller
{
Account = ServiceAccount.LocalSystem
});
var installContext = new InstallContext(
serviceName + ".install.log", null);
installContext.Parameters["assemblypath"] =
Assembly.GetEntryAssembly().Location;
installer.Context = installContext;
return installer;
}
}
in the main entry of the service project:
if (Environment.UserInteractive)
{
bool install = false;
bool uninstall = false;
string serviceName = "YourDefaultServiceName";
var p = new OptionSet()
.Add<bool>("i|install", "Install Windows Service", i => install = i)
.Add<bool>("i|install=", "Install Windows Service", i => install = i)
.Add<bool>("u|uninstall", "Uninstall Window Service", u => uninstall = u)
.Add<string>("sn|service_name=", "Service Name", n => serviceName = n);
p.Parse(args);
if (install)
{
BasicServiceInstaller.Install(serviceName);
return;
}
else if (uninstall)
{
BasicServiceInstaller.Uninstall(serviceName);
return;
}
// if no install or uninstall commands so start the service as a console.
var host = new YourService();
host.Start(args);
Console.ReadKey();
}
else
{
ServiceBase.Run(new HotspotCenterService());
}
Without exact information, I would suggest following:
check the exception details to see what exactly went wrong
use Fusion Log Viewer, to see which assemblies failed binding
check whether your probing configuration matches your deployment
Probing is configured as described here.
I need to be able to publish an SSDT project programmatically. I am looking at using Microsoft.Build to do so but can not find any documentation. It seems pretty simple to create the .dacpac, but how would I either publish to an existing database or at the very least to a .sql file. The idea is to have it do what it does when I right click on the project and select publish. It should compare with a selected database and generate an upgrade script.
This is what I have so far to create the .dacpac:
partial class DBDeploy
{
Project project;
internal void publishChanges()
{
Console.WriteLine("Building project " + ProjectPath);
Stopwatch sw = new Stopwatch();
sw.Start();
project = ProjectCollection.GlobalProjectCollection.LoadProject(ProjectPath);
project.Build();
//at this point the .dacpac is built and put in the debug folder for the project
sw.Stop();
Console.WriteLine("Project build Complete. Total time: {0}", sw.Elapsed.ToString());
}
}
Essentially I am trying to do what this MSBuild Example shows but in code.
Sorry that this is all I have. The doecumentation on the Build classes is very poor. Any help would be appreciated.
Thanks.
I had to do something similar to this because VSDBCMD which we previously used does not deploy to SQL Server 2012 and we needed to support it. What I found was the Microsoft.SqlServer.Dac assembly which seems to come as part of the SQL Server data tools (http://msdn.microsoft.com/en-us/data/tools.aspx)
When you run this on the client machine you will need the full version of the .NET 4 framework and the SQL CLR types and SQL T-SQL ScriptDOM pack found here: http://www.microsoft.com/en-us/download/details.aspx?id=29065
Code below is from a mockup I made for testing the new deployment method and deploys a given .dacpac file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Dac;
using System.IO;
namespace ConsoleApplication3
{
class Program
{
private static TextWriter output = new StreamWriter("output.txt", false);
static void Main(string[] args)
{
Console.Write("Connection String:");
//Class responsible for the deployment. (Connection string supplied by console input for now)
DacServices dbServices = new DacServices(Console.ReadLine());
//Wire up events for Deploy messages and for task progress (For less verbose output, don't subscribe to Message Event (handy for debugging perhaps?)
dbServices.Message += new EventHandler<DacMessageEventArgs>(dbServices_Message);
dbServices.ProgressChanged += new EventHandler<DacProgressEventArgs>(dbServices_ProgressChanged);
//This Snapshot should be created by our build process using MSDeploy
Console.WriteLine("Snapshot Path:");
DacPackage dbPackage = DacPackage.Load(Console.ReadLine());
DacDeployOptions dbDeployOptions = new DacDeployOptions();
//Cut out a lot of options here for configuring deployment, but are all part of DacDeployOptions
dbDeployOptions.SqlCommandVariableValues.Add("debug", "false");
dbServices.Deploy(dbPackage, "trunk", true, dbDeployOptions);
output.Close();
}
static void dbServices_Message(object sender, DacMessageEventArgs e)
{
output.WriteLine("DAC Message: {0}", e.Message);
}
static void dbServices_ProgressChanged(object sender, DacProgressEventArgs e)
{
output.WriteLine(e.Status + ": " + e.Message);
}
}
}
This seems to work on all versions of SQL Server from 2005 and up. There is a similar set of objects available in Microsoft.SqlServer.Management.Dac, however I believe this is in the previous version of DACFx and is not included in the latest version. So use the latest version if you can.
We need a way tell msbuild how and where to publish. Open your project in Visual Studio and begin to Publish it. Enter all needed info in the dialog, including your DB connection info and any custom SQLCMD variable values. Save Profile As... to a file, e.g. Northwind.publish.xml. (You may then Cancel.) Now we can use this and the project file to build and publish:
// Create a logger.
FileLogger logger = new FileLogger();
logger.Parameters = #"logfile=Northwind.msbuild.log";
// Set up properties.
var projects = ProjectCollection.GlobalProjectCollection;
projects.SetGlobalProperty("Configuration", "Debug");
projects.SetGlobalProperty("SqlPublishProfilePath", #"Northwind.publish.xml");
// Load and build project.
var dbProject = ProjectCollection.GlobalProjectCollection.LoadProject(#"Northwind.sqlproj");
dbProject.Build(new[]{"Build", "Publish"}, new[]{logger});
This can take awhile and may appear to get stuck. Be patient. :)
You should use SqlPackage.exe to publish your dacpac.
SqlPackage.exe
/Action:Publish
/SourceFile:C:/file.dacpac
/TargetConnectionString:[Connection string]
Also instead of passing too many parameters you could save your settings into DAC Publish Profile (this can be done from visual studio)
I wanted to build and publish a database based on a sqlproj file and log helpful information to console. Here's what I arrived at:
using Microsoft.Build.Framework;
using Microsoft.Build.Execution;
public void UpdateSchema() {
var props = new Dictionary<string, string> {
{ "UpdateDatabase", "True" },
{ "PublishScriptFileName", "schema-update.sql" },
{ "SqlPublishProfilePath", "path/to/publish.xml") }
};
var projPath = "path/to/database.sqlproj";
var result = BuildManager.DefaultBuildManager.Build(
new BuildParameters { Loggers = new[] { new ConsoleLogger() } },
new BuildRequestData(new ProjectInstance(projPath, props, null), new[] { "Publish" }));
if (result.OverallResult == BuildResultCode.Success) {
Console.WriteLine("Schema update succeeded!");
}
else {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Schema update failed!");
Console.ResetColor();
}
}
private class ConsoleLogger : ILogger
{
public void Initialize(IEventSource eventSource) {
eventSource.ErrorRaised += (sender, e) => {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Message);
Console.ResetColor();
};
eventSource.MessageRaised += (sender, e) => {
if (e.Importance != MessageImportance.Low)
Console.WriteLine(e.Message);
};
}
public void Shutdown() { }
public LoggerVerbosity Verbosity { get; set; }
public string Parameters { get; set; }
}
This is for .NET 4 and above. Be sure and include assembly references to Microsoft.Build and Microsoft.Build.Framework.