zoukankan      html  css  js  c++  java
  • [转]SSIS ConnectionManager.ConnectionString Property

    本文转自: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.SqlServer.Dts.Runtime
    Assembly:  Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)

    Syntax
     
     
    public string ConnectionString { get; set; }
    

    Property Value

    Type: System.String A String that contains the connection string value.

    The format and contents of the connection string 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 Data Tools, create a package, and then create a connection manager of the appropriate type within that package. Next, in the Properties window, examine the ConnectionString property of the connection manager that you just created.

    The following code example adds an OLE DB connection manager, and then sets the connection manager name and connection string properties.

     
    // 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 formatted similar to the following:

    String myConnString = @"C:Program FilesMicrosoft SQL Serverorders.xml";

    Whereas for an OLE DB connection, the connection string contains values similar to the following connection string:

    String myConnString = "Server=MYSERVER;Provider=SQLOLEDB.1;Pwd= xxxxxxx;User ID= xxxxx;Initial Catalog=mySource;OLE DB Services=-2";

    And an ODBC connection string may look similar to the following:

    String myConnString = "DSN=LocalServer;DATABASE=MySource;PWD=xxxxxxx;UID=xxxxx";

    In the properties dialog box of a connection in the SSIS Designer, this value appears as the Connection String property.

    For a list of all connection managers included with the product, see Integration Services (SSIS) Connections.

    The following code example creates a FileSystemTask as an Executable in a package. The FileSystemTask copies a test folder that contains two subfolders and a .txt file, to another folder. The source and destinations are existing folders. Therefore, theIsDestinationPathVariable and IsSourcePathVariable are set to false, and the Destination and Source properties are set to reference two FILE connection managers that have been created and have had their connection strings set to reference Stringscontaining the paths.

     
    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();
            }
        }
    }
    
  • 相关阅读:
    swiper获取当前的index ( loop=true时,)
    解决ios浏览器页面滚动到底部或顶部后,页面局部滑动失效的问题
    js实现全屏与退出全屏
    Ueditor 关于视频上传相关问题
    git拉取单个子目录
    XShell上传文件到Linux服务器上
    Debian中安装MySQL服务器
    lamda表达式的由来
    工具类--验证码工具类
    工具类--线程相关工具类
  • 原文地址:https://www.cnblogs.com/freeliver54/p/3684903.html
Copyright © 2011-2022 走看看