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 as를 Executable 만듭니다. 두 FileSystemTask 하위 폴더와 .txt 파일이 포함된 테스트 폴더를 다른 폴더에 복사합니다. 원본 및 대상은 기존 폴더입니다. 따라서 IsDestinationPathVariableIsSourcePathVariable 만들어지고 해당 연결 문자열이 경로를 포함하는 참조로 DestinationfalseSource 설정된 두 개의 FILE 연결 관리자를 참조 Strings 하도록 설정됩니다.

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) 연결을 참조하세요.

적용 대상