SSIS Connection Manager.Connection String Property

14553 ワード

本論文は、http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.dts.runtime.connectionmanager.connectionstring.aspxから回転する。
 
 
Gets or sets the connection string used to establish a connection to a data source.
 
Namespace:   Microsoft.Sql Server.Dts.Runtime Asssemble:  Microsoft.Sql Server.ManagedDT (in Microsoft.Sql Server.ManagedDTS.dll)
Syntax
 
同前
C++
安徽省にある地名。
JScript
VB
 
public string ConnectionString { get; set; }
Property Value Type:
 
System.String
A String that contains the connection string value.
Remarks
 
The format and contens of the connection streing depend on the data provider,the data source,and the type of connection manager that is being created.To view a sample connection string,in SQL Server Daols,preactionant therectionant Next,in the Properties window,examine the Connection String property of the connection manager that you just created.
The follwing code example adds an One DB connection manager、and then sets the connection name and connection string properties.
同前
VB
 
// Add the OLE DB connection manager.
ConnectionManager adventureWorks = package.Connections.Add("OLEDB");
// Set stock properties.
adventureWorks.Name = "OLEDBConnection";
adventureWorks.ConnectionString = @"Provider=SQLNCLI10;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=AdventureWorks;Data Source=(local);Auto Translate=False;";
For an XML connection string、the connection string value is formated simiar to the follwing:
String myConString=@「C:\Program Files\Microsoft SQL Server\orders.xml」
Whears for an OleE DB connection、the connection string contains values simiar to the follwing connection string:
String myConString="Server=MYSERVER;Provider=SQLOLEDB.1;Pwd=xxxxxx;User ID=xxxxxx;Initial Catalog=mySource;One DB Services=-2"
And an ODBC connection string may look simiar to the follwing:
String myConString="DSN=LocalServer;DATABASE=MySource;PWD=xxxxxx;UID=xxxx"
In the properties dialog box of a connection in the SSIS Designer,this value appars as the Connection String property
For a list of all connection managers includ with the product,see  Integration Services(SSIS)Connection.
Examples
 
The follwing code example creates a  FileSystem Task as an  Executable in a package.The  FileSystem Task copies a test folder that contains two subfolders and a.txt file,to another folder.The source and destination s are existing folders.The refore,the Is Destination PathVarable and  Is SourcePathVarable arset to false,and the  Destination and  ソurce properties are set to reference two FILE connection manage rs that have been created and have have had their connection streings set to reference Stringscontaining the paths.
同前
VB
 
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Tasks.FileSystemTask;

namespace FileSystemTask_API
{
    class Program
    {
        static void Main(string[] args)
        {
            String sourceDir = @"C:\TestFolder";
            String destDir = @"C:\MyNewTestFolder";

            Package pkg = new Package();
            Executable exec1 = pkg.Executables.Add("STOCK:FileSystemTask");
            TaskHost th = exec1 as TaskHost;
            
            // Show how to set properties using the TaskHost
             // Properties. Set the properties to copy an existing
             // folder, which contains two subfolders and a .txt file,
            // to another existing folder on the C:\ drive.

            // The source or destination files are not in a variable,
            // so set IsSourcePathVariable and 
            // IsDestinationPathVariable to false.
            th.Properties["IsSourcePathVariable"].SetValue(th, false);
            th.Properties["IsDestinationPathVariable"].SetValue(th, false);

            // Create the File connection manager for the source.
            ConnectionManager cm = pkg.Connections.Add("FILE");
            cm.Name = "The FILE connection manager";
            cm.ConnectionString = sourceDir;
            cm.Properties["FileUsageType"].SetValue(cm, DTSFileConnectionUsageType.FolderExists);

            // Create the File connection manager for the destination.
            ConnectionManager cmdest = pkg.Connections.Add("FILE");
            cmdest.Name = "The destination FILE connection manager";
            cmdest.ConnectionString = destDir;
            cmdest.Properties["FileUsageType"].SetValue(cmdest, DTSFileConnectionUsageType.FolderExists);

            // Set the source property and destination properties
            // for the task.
            th.Properties["Source"].SetValue(th, cm.Name);
            th.Properties["Destination"].SetValue(th, cmdest.Name);

            // The operation to perform is to copy all the files and
             // subfolders in a folder.
            // Do not overwrite the destination information 
            // if it exists.
            th.Properties["Operation"].SetValue(th, DTSFileSystemOperation.CopyDirectory);
            th.Properties["OperationName"].SetValue(th, "Copy TestFolder");
            th.Properties["OverwriteDestinationFile"].SetValue(th, false);

            // Set the attribute of the folder to be read-only.
            th.Properties["Attributes"].SetValue(th, DTSFileSystemAttributes.ReadOnly);
            // Multiple attributes can be set. The next line of code,
            // commented out, shows how to do that.
            //th.Properties["Attributes"].SetValue(th, DTSFileSystemAttributes.ReadOnly | DTSFileSystemAttributes.Hidden);

            // Run the task and copy the folder.
            DTSExecResult result = pkg.Execute();
        }
    }
}
See Also
 
Reference
Connection Manager Class
Microsoft.Sql Server.Dts.Runtime Namespace