Array Parameter Sample
Sometimes it is useful to create, update, or delete a set of rows in a database. There are several approaches you could use to achieve that goal. One of them is to pass an array of information from a client to a common language runtime (CLR) integration stored procedure on the server by using a CLR integration user-defined data type. The nature of such user-defined data types limits the size of the data provided to the server to 8000 bytes. Therefore, this approach is not satisfactory for large or complex data. For more information, see the contact creation stored procedure in the AdventureWorks Cycles CLR Layer sample. If the data that is being manipulated is small and simple, this approach can be much more efficient than calling a stored procedure for each row. By passing an array, the order of data is preserved for those applications where the order significant.
This sample contains the following:
ContactTypeNamesuser-defined data type. This contains a list of desired contact type names.
usp_EnsureContactTypeNamesstored procedure implemented as a Microsoft Visual C# or Microsoft Visual Basic method. This accepts an instance of the
ContactTypeNamesuser-defined data type and inserts new rows in the Person.ContactType table for any contact names that are contained in the user-defined data type instance which are not already present in the table.
TestArrayParameterconsole application. This creates an instance of the
ContactTypeNamesuser-defined data type based on the command line parameters passed in, and then invokes the
usp_EnsureContactTypeNamesstored procedure by passing the user-defined data type instance as a parameter.
Install directory: drive:\Program Files\Microsoft SQL Server\90\Samples\Engine\Programmability\CLR\ArrayParameter\
Before running this sample, make sure the following software is installed:
Microsoft SQL Server 2005 or Microsoft SQL Server 2005 Express Edition (SQL Server Express). You can obtain SQL Server Express free of charge from the SQL Server 2005 Express Edition Documentation and Samples Web site.
The AdventureWorks database which is included with SQL Server 2005, and is also available at the SQL Server Developer Web site.
The SQL Server 2005 Database Engine samples. These samples are included with SQL Server 2005. You can download the latest version of the samples at the SQL Server Developer Web site.
.NET Framework SDK 2.0 or Microsoft Visual Studio 2005. You can obtain .NET Framework SDK free of charge. See Installing the .NET Framework SDK.
If you have not already created a strong name key file, generate the key file using the following instructions.
- Open a Microsoft Visual Studio 2005 command prompt. Click Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt.
-- or --
Open a Microsoft .NET Framework command prompt. Click Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt.
- Use the change directory command (CD) to change the current directory of the command prompt window to the folder where the samples are installed.
Note: To determine the folder where samples are located, click the Start button, point to All Programs, point to Microsoft SQL Server, 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\100\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.
Compile the sample by using Visual Studio 2005 and the provided Visual Studio solution, or by using Microsoft MSBuild, which is included in the .NET Framework SDK 2.0. Run commands similar to the following at a .NET Framework command prompt:
msbuild /nologo /verbosity:quiet /property:Configuration=Debug CS\ArrayParameter.sln
Make sure that the AdventureWorks database is installed.
If you did not install the SQL Server Database Engine samples in the default location, modify the path in the CREATE ASSEMBLY part of the script in Scripts\InstallCS.sql to refer to the location where the samples were installed.
If you are not an administrator for the SQL Server instance you are using, you must have an administrator grant you CreateAssembly permission to complete the installation.
Open the scripts\installCS.sql or scripts\installVB.sql file, depending on whether you compiled the Visual C# project or the Visual Basic project, in SQL Server Management Studio. Execute the script contained in the file, or execute a command similar to the following in a command prompt window:
sqlcmd -E -I -i Scripts\InstallCS.sql
The common language runtime for SQL Server 2005 or SQL Server Express must be enabled for this sample to work correctly.
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. Sample applications and assemblies should not be connected to or used with your production SQL Server database or your report server without the permission of the system administrator.