ConnectionManager.ConnectionString プロパティ

定義

データ ソースへの接続を確立するために使用する接続文字列を取得します。値の設定も可能です。

public:
 property System::String ^ ConnectionString { System::String ^ get(); void set(System::String ^ value); };
[Microsoft.SqlServer.Dts.Runtime.Localization.LocalizablePropertyDescription(typeof(Microsoft.SqlServer.Dts.Runtime.Localized), "ConnectionStringDesc")]
[System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.All)]
public string ConnectionString { get; set; }
[<Microsoft.SqlServer.Dts.Runtime.Localization.LocalizablePropertyDescription(typeof(Microsoft.SqlServer.Dts.Runtime.Localized), "ConnectionStringDesc")>]
[<System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.All)>]
member this.ConnectionString : string with get, set
Public Property ConnectionString As String

プロパティ値

接続文字列の値を含む文字列。

属性

次のコード例では、パッケージの FileSystemTask として Executable を作成します。 FileSystemTask 2 つのサブフォルダーと 1 つの.txt ファイルを含むテスト フォルダーを別のフォルダーにコピーします。 コピー元とコピー先は既存のフォルダーです。 したがって、作成され、IsDestinationPathVariableIsSourcePathVariableその接続文字列がパスを含む参照にfalse設定されている 2 つの FILE 接続マネージャーを参照するようにStringsDestinationSourceおよびプロパティが設定されます。

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();  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  
Imports Microsoft.SqlServer.Dts.Tasks.FileSystemTask  

Namespace FileSystemTask_API  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim sourceDir As String =  "C:\TestFolder"   
            Dim destDir As String =  "C:\MyNewTestFolder"   

            Dim pkg As Package =  New Package()   
            Dim exec1 As Executable =  pkg.Executables.Add("STOCK:FileSystemTask")   
            Dim th As TaskHost =  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.  
            Dim cm As ConnectionManager =  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.  
            Dim cmdest As ConnectionManager =  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.  
            Dim result As DTSExecResult =  pkg.Execute()   
        End Sub  
    End Class  
End Namespace  

注釈

接続文字列の形式と内容は、データ プロバイダー、データ ソース、および作成される接続マネージャーの種類によって異なります。 サンプル接続文字列を表示するには、SQL Server Data Toolsでパッケージを作成し、そのパッケージ内に適切な種類の接続マネージャーを作成します。 次に、[プロパティ] ウィンドウで、作成した接続マネージャーの ConnectionString プロパティを調べます。

次のコード例では、OLE DB 接続マネージャーを追加し、接続マネージャー名プロパティおよび接続文字列プロパティを設定します。

// 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;";  
' Add the OLE DB connection manager.  
Dim adventureWorks As ConnectionManager =  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;"  

XML 接続文字列の場合、接続文字列値は、次のように書式設定されます。

String myConnString = @"C:\Program Files\Microsoft SQL Server\orders.xml";

OLE DB 接続の場合、接続文字列には、次の接続文字列のような値が含まれます。

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

また、ODBC 接続文字列は、次のようになります。

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

SSIS デザイナーの接続のプロパティ ダイアログ ボックスに、この値が 接続文字列 プロパティとして表示されます。

製品に含まれるすべての接続マネージャーの一覧については、「 Integration Services (SSIS) 接続」を参照してください。

適用対象