Sql Server Custom Connection Manager Sample
The SQL Server Custom Connection Manager sample demonstrates how to create a custom connection manager, the Sql Connection Manager, and its associated user interface. This sample is not supported on Itanium-based operating systems.
For more information about creating a custom connection manager, see Creating a Custom Connection Manager. For general information about the use of connection managers in Integration Services, see Integration Services Connections and Connection Managers.
This custom connection manager connects to an available instance of Microsoft SQL Server by using the SqlClient .NET Framework Data Provider, and returns an open SqlConnection object from its AcquireConnection method. When you create a new instance of the Sql Connection Manager in a package, its custom user interface prompts you for the server name and a database name. The sample connects only to a default instance of SQL Server, and uses only Windows Authentication.
This code sample implements the following functionality:
Overriding of the ConnectionManagerBase class.
|Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples.|
If you already know how to locate, build, and install code samples, you can go directly to the section Testing the Sample, and read about how to configure and run the code sample
If the code sample was installed to the default location, the sample is located in the following directory:
C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\\Programming Samples\Control Flow\SqlConnectionManager Sample
The C# solution for the code sample is located in the SqlConnMgrCS directory, and the Visual Basic solution is located in the SqlConnMgrVB directory.
For information about the two-step process required to install the samples, see Installing Samples. To obtain the latest version of the samples, including new samples released after the original release of SQL Server 2005, see SQL Server 2005 Samples and Sample Databases (April 2006).
If you have not already generated a strong name key file in the Samples folder, use the following procedure to generate this key file. The sample projects are configured on the Signing tab of the Project Properties dialog box to sign assemblies at build time with this key file.
To open a Microsoft Visual Studio 2005 command prompt, click Start, point to All Programs, point to Microsoft Visual Studio 2005, point to Visual Studio Tools, and then click Visual Studio 2005 Command Prompt.
- or -
To open a Microsoft .NET Framework command prompt, click Start, point to All Programs, point to Microsoft .NET Framework SDK v2.0, and then click SDK Command Prompt.
At the command prompt, use the change directory (CD) command to change the current folder of the Command Prompt window to the Samples folder. The key file that you create in this folder will be used by all SQL Server 2005 code samples.
Note: To determine the folder where samples are located, click Start, point to All Programs, point to Microsoft SQL Server 2005, point to Documentation and Tutorials, and then click Samples Directory. If the default installation location was used, the samples are located in <system_drive>:\Program Files\Microsoft SQL Server\90\Samples.
At the command prompt, run the following command to generate the key file:
sn -k SampleKey.snk
Important: For more information about the strong-name key pair, see "Security Briefs: Strong Names and Security in the .NET Framework" in the .NET Development Center on MSDN.
You will need the public key token from the key file in a subsequent step. To obtain the public key token, first extract the public key from the key file to a new file by running the following command at the command prompt:
sn -p SampleKey.snk SampleKeyPublic.snk
Now display the public key token from the new file by running the following command at the command prompt:
sn -t SampleKeyPublic.snk
Copy the public key token to the clipboard or save it for later use.
From the File | Open menu, click Project and open the solution file SqlConnMgrVB.sln or SqlConnMgrCS.sln.
In the Solution Explorer, select the SqlConnMgrVB or SqlConnMgrCS project.
Locate the DtsConnection attribute before the class declaration in the SqlConnMgrCS.cs file or the SqlConnMgrVB.vb file and replace the alphanumeric value of the Public Key Token in the UITypeName property of the attribute with the public key token obtained earlier from the key file.
On the Build menu, click Build Solution.
This sample is provided in both Visual Basic and C#. To distinguish the assemblies for each version of the sample, the name of the output assembly has CS or VB appended. After successfully building the component, follow these steps in order to add it as a connection manager in a package in Business Intelligence Development Studio.
Open a Command Prompt window.
Type the following commands to install the C# version of the component and the user interface into the GAC:
gacutil.exe -iF " C:\Program Files\Microsoft SQL Server\90\Samples\Integration Services\Programming Samples\Control Flow\SqlConnectionManager Sample\SqlConnMgrCS\bin\Debug\SqlConnMgrCS.dll" gacutil.exe -iF " C:\Program Files\Microsoft SQL Server\90\Samples\Integration Services\Programming Samples\Control Flow\SqlConnectionManager Sample\SqlConnMgrCS\bin\Debug\SqlConnMgrUICS.dll"
- or -
Type the following commands to install the Visual Basic version of the component and the user interface into the GAC:
gacutil.exe -iF " C:\Program Files\Microsoft SQL Server\90\Samples\Integration Services\Programming Samples\Control Flow\SqlConnectionManager Sample\SqlConnMgrVB\bin\Debug\SqlConnMgrVB.dll" gacutil.exe -iF " C:\Program Files\Microsoft SQL Server\90\Samples\Integration Services\Programming Samples\Control Flow\SqlConnectionManager Sample\SqlConnMgrVB\bin\Debug\SqlConnMgrUIVB.dll"
You can now test the custom connection manager in a package.
In the connection managers area of SSIS Designer, right-click, select New Connection, and in the list of available connection types, select SQL. Click OK.
Edit the new connection manager. In the Sql Connection Manager Editor, provide the name of an available default instance of the SQL Server Database Engine and of an available database.