Method1:
Directly ask the Server
String packageName = "Z_Test1 ";
Object pVarPersistStgOfHost = null;
DTS. PackageClass package = new DTS. PackageClass ();
Package. LoadFromSQLServer ("YourServerName", "UserName", "Password", DTS. DTSSQLServerStorageFlags. DTSSQLStgFlag_UseTrustedConnection, null, null, packageName, ref pVarPersistStgOfHost );
Try
{
// Execute the package
Console. WriteLine ("DTS Package Executing ..");
Package. Execute ();
Console. WriteLine ("DTS Package Completed ");
Console. ReadLine ();
}
Catch (Exception ex)
{
Console. WriteLine (ex. Message );
}
Finally
{
Package. UnInitialize ();
Package = null;
}
Method2:
It can be used through packaging DTS as A. dts file.
Try
{
DTS. Package2Class package = new DTS. Package2Class ();
String filename = @ "c: \ test1.dts ";
String password = null;
String packageID = null;
String versionID = null;
String packageName = "DTSTestPackage ";
Object pVarPersistStfOfHost = null;
Package. LoadFromStorageFile (
Filename,
Password,
PackageID,
VersionID,
Name, ref
PVarPersistStfOfHost );
Package. Execute ();
Package. UnInitialize ();
Package = null;
}
Catch (System. Runtime. InteropServices. COMException e)
{
Console. WriteLine (e );
}
Catch (System. Exception e)
{
Console. WriteLine (e );
}
As mentioned above, Method1 has passed the verification Verification OK, and Method2 has always been a problem.
Although DTS can be used easily, if we integrate multiple DTS into a single Jobs, we can use the SQL Server Schedule for DTS to run on its own. In this way, it will be more convenient. You don't need to use Method1 to use data transmission, but you only need to use a job to complete the operation.
However, I have not found C # To use the SQL Jobs resources. I hope some friends with the resources can provide them.