[转]SSIS ConnectionManager.ConnectionString Property
2014-04-24 10:49
459 查看
本文转自: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
C#
C++
F#
JScript
VB
Remarks
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.
C#
VB
For an XML connection string, the connection string value is formatted similar to the following:
String myConnString = @"C:\Program Files\Microsoft SQL Server\orders.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.
Examples
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.
C#
VB
See Also
Microsoft.SqlServer.Dts.Runtime Namespace
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
C#
C++
F#
JScript
VB
public string ConnectionString { get; set; }
Property Value
Type: System.String A String that contains the connection string value.Remarks
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.
C#
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 formatted similar to the following:
String myConnString = @"C:\Program Files\Microsoft SQL Server\orders.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.
Examples
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.
C#
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
ConnectionManager ClassMicrosoft.SqlServer.Dts.Runtime Namespace
相关文章推荐
- [SSIS 2005]SSIS Error The AcquireConnection method call to the connection manager failed with error code 0xC0202009
- SSIS 错误代码 DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER
- _nm_object_get_property: Error getting 'State' for /org/freedesktop/NetworkManager/ActiveConnection/
- Dynamic ConnectionString in SSIS / 使用动态 DB Connection
- Data Flow ->> Excel Connection遇到错误:[Excel Source [16]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.....
- SSIS 尝试运行官方的示例 DataCleaning.sln项目0xC0202009 at DataCleaning, Connection manager "LocalHost.AdventureWorks": An OLE DB er
- MSDN中关于读取web.config的那块,System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString
- SSIS:SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. Error code 0xC020801C,0xC0209303
- The Excel Connection Manager is not supported in the 64-bit version of SSIS, as no OLE DB provider i
- [转]SSIS error DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER when connecting to Oracle data source
- The Excel Connection Manager is not supported in the 64-bit version of SSIS, as no OLE DB provider i 推荐
- SSIS错误之"The Excel Connection Manager is not supported in the 64-bit version of SSIS"
- ConnectionStringManager (build, edit connectionString in app.config file)
- SSIS 尝试运行官方的示例 DataCleaning.sln项目0xC0202009 at DataCleaning, Connection manager "LocalHost.Adventure
- ConnectionString Property - ADO
- SSIS 错误代码 DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER(0xC0202009)
- ConnectionString Property - ADO
- DriverManager.getConnection(url_String, user_String, password_String)活动图
- The Excel Connection Manager is not supported in the 64-bit version of SSIS
- SSIS 错误代码 DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER