Aracılığıyla paylaş


ConnectionManager.ConnectionString Özelliği

Alır veya ayarlar bağlantı dize bir veri kaynağına bir bağlantı kurmak için kullanılır.

Ad Alanı:  Microsoft.SqlServer.Dts.Runtime
Derleme:  Microsoft.SqlServer.ManagedDTS (Microsoft.SqlServer.ManagedDTS içinde.dll)

Sözdizimi

'Bildirim
Public Property ConnectionString As String
    Get
    Set
'Kullanım
Dim instance As ConnectionManager
Dim value As String

value = instance.ConnectionString

instance.ConnectionString = value
public string ConnectionString { get; set; }
public:
property String^ ConnectionString {
    String^ get ();
    void set (String^ value);
}
member ConnectionString : string with get, set
function get ConnectionString () : String
function set ConnectionString (value : String)

Özellik Değeri

Tür: System.String
A dize içeren bağlantı dizesi değer.

Açıklamalar

Biçimi ve içeriği bağlantının dize veri sağlayıcı, veri kaynağı ve oluşturulan Bağlantı Yöneticisi türüne bağlıdır.Bir örnek bağlantı görüntülemek için dize, te BI Development Studio, paket oluşturabilir ve sonra bir Bağlantı Yöneticisi bu paket içindeki uygun türü. Daha sonra Properties penceresinde incelemek bağlantıdize , yeni oluşturduğunuz Bağlantı Yöneticisi'nin özellik.

Aşağıdaki kod örneği ekler bir ole db Bağlantı Yöneticisi'ni ve sonra Bağlantı Yöneticisi adı ve bağlantı ayarlar dize özellikleri.

// Add the OLE DB connection manager.
ConnectionManager AdventureWorks2008R2 = package.Connections.Add("OLEDB");
// Set stock properties.
AdventureWorks2008R2.Name = "OLEDBConnection";
AdventureWorks2008R2.ConnectionString = @"Provider=SQLNCLI10;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=AdventureWorks2008R2;Data Source=(local);Auto Translate=False;";
' Add the OLE DB connection manager.
Dim AdventureWorks2008R2 As ConnectionManager =  package.Connections.Add("OLEDB") 
' Set stock properties.
AdventureWorks2008R2.Name = "OLEDBConnection"
AdventureWorks2008R2.ConnectionString = "Provider=SQLNCLI10;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=AdventureWorks2008R2;Data Source=(local);Auto Translate=False;"

xml bağlantısı için dize, bağlantı dize değeri biçimlendirilmiş aşağıdakine benzer:

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

Oysa bir ole db bağlantı, bağlantı için dize için aşağıdaki bağlantıyı benzer değerleri içeren dize:

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

Ve bir odbc bağlantısı dize aşağıdakine benzeyebilir:

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

SSIS Tasarımcısı'nda bir bağlantı özellikleri iletişim kutusunda, bu değeri olarak görünür Bağlantı dizesi özellik.

Ürünle birlikte gelen tüm bağlantı yöneticileri listesi için bkz: Connection Managers.

Örnekler

Aşağıdaki kod örneği oluşturur bir FileSystemTask olarak bir Executable paket.FileSystemTask İki alt klasörler ve başka bir klasör için bir .txt dosyası içeren bir sınama klasörü kopyalarKaynak ve hedefleri var klasörlerdir.Bu nedenle, IsDestinationPathVariable ve IsSourcePathVariable küme yanlışve Destination ve Source Özellikler ares ayarlamak başvuracak iki dosya bağlantı yöneticileri yaratılmış ve olduğu kendi bağlantı dizeleri ayarlamak için başvuru dizeleri yolları içeren.

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