Oracle TVF Sample
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]
This sample works only with SQL Server 2005 and SQL Server "Katmai". It will not work with any version of SQL Server earlier than SQL Server 2005.
In some enterprise scenarios, it is useful to integrate data from other database management systems with data that is stored in Microsoft SQL Server. This sample demonstrates how to invoke the managed code interface to Oracle to expose the results of any Oracle
query as a table-valued function in SQL Server. This approach makes it easy to join data from both Oracle and SQL Server in a relatively simple SELECT statement that you run on SQL Server.
This sample contains the GetDataFromOracle
table-valued function. This function uses the managed Oracle provider to run arbitrary Oracle queries against an Oracle database and provide the results in table form.
Install directory: C:\Program Files\Microsoft SQL Server\100\Samples\Engine\Programmability\CLR\OracleTVF\
Jane is a developer for Adventure Works Cycles. She has to integrate data from an Oracle database with data that is stored in a SQL Server database.
Transact-SQL, Visual C# and Visual Basic.
The Oracle TVF sample uses the following features of Microsoft SQL Server.
||Common language runtime, Oracle managed provider, Transact-SQL
Before running this sample, make sure that the following software is installed:
- Microsoft SQL Server or Microsoft SQL Server Express. You can obtain SQL Server Express free of charge from the SQL Server Express Documentation and Samples
- The SQL Server Database Engine samples. These samples are included with SQL Server. You can download the latest version of the samples at the SQL Server Developer
- .NET Framework SDK 2.0 or Microsoft Visual Studio 2005. You can obtain the .NET Framework SDK free of charge. For more information, see
Installing the .NET Framework SDK.
A server that is running Oracle 10g. If you have an earlier version of Oracle installed, you will have to modify the table and columns that are accessed to match an existing table on your older server. This sample might not work on x64-based hardware that is
using Oracle versions earlier than to 10g. If you want to use this sample on Windows Vista, contact your Oracle customer service representative for information about availability of Oracle 10g on Windows Vista.
Building the Sample
If you have not already created the strong-name key file UnsafeSampleKey.snk
, generate the key file by using the following procedure.
To generate a strong name key file
- 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—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.
- At the command prompt, use the change directory (CD) command to change the current folder of the Command Prompt window to the Samples folder.
Note: To determine the folder where the samples are located, click Start, 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 <drive>:\Program Files\Microsoft SQL Server\100\Samples.
- At the command prompt, run the following command to generate the key file:
sn -k UnsafeSampleKey.snk ** Important: For more information about the strong-name key pair, see "Security Briefs: Strong Names and Security in the .NET Framework" at the Microsoft .NET Development Center on MSDN.
To build the Oracle TVF sample
- 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\OracleTVF.sln
- Make sure that the AdventureWorks database is installed.
- If you did not install the SQL Server 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 that you are using, you must have an administrator grant you
CreateAssembly permissions 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 Microsoft . Run the script that is contained in the file, or run a command similar to the following in
a Command Prompt window: sqlcmd -E -I -i Scripts\InstallCS.sql
Running the Sample
To run the Oracle TVF sample
- Open the Scripts\Test.sql file in Microsoft Management Studio or a text editor such as Notepad. Modify the script by replacing <server name>, <user name>, and <password> with the name of the Oracle server that you
use and the credentials that you use on that server. Run the script in Management Studio, or save the script from Notepad. Then, run a command similar to the following in a Command Prompt window:
sqlcmd -E -I -i Scripts\Test.sql
Removing the Sample
To remove the Oracle TVF sample
- Open the scripts\cleanup.sql file in Management Studio. Run the script that is contained in the file, or run the following command in a Command Prompt window:
sqlcmd -E -I -i Scripts\cleanup.sql
The common language runtime for SQL Server 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.
© 2007 Microsoft Corporation. All rights reserved.