Data transmission using SQL through VS. NET protocol

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.