MS SQL Server
  Home arrow MS SQL Server arrow Page 4 - Developing Managed Code and Executing With...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

Developing Managed Code and Executing Within Microsoft SQL Server 2000
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 11
    2005-12-15

    Table of Contents:
  • Developing Managed Code and Executing Within Microsoft SQL Server 2000
  • Developing the .NET component
  • How to deploy the .NET component
  • How to call .NET component from within SQL Server 2000
  • Understanding the concept

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Developing Managed Code and Executing Within Microsoft SQL Server 2000 - How to call .NET component from within SQL Server 2000


    (Page 4 of 5 )

    After completing all of the above steps, open up your query analyzer and type the following Transact-SQL code, to call the component:

    DECLARE  @ExecutionResult INT, @errorSource VARCHAR(100), @errorDescription VARCHAR(100), @result VARCHAR(200),@hnd INT
     
    EXEC @ExecutionResult = sp_OACreate 'MySample.CSample', @hnd OUTPUT
     
    EXEC @ExecutionResult = sp_OAMethod @hnd, 'getSum', @result OUTPUT, 10, 20
     
    EXEC @ExecutionResult = sp_OADestroy @hnd
     
    SELECT @result

    Just press F5 to execute the script and it should give you a result with a value of 30.  You can modify the above code with better error handling as follows:

    DECLARE  @ExecutionResult INT, @errorSource VARCHAR(100), @errorDescription VARCHAR(100), @result VARCHAR(200),@hnd INT
     
    EXEC @ExecutionResult = sp_OACreate 'MySample.CSample', @hnd OUTPUT
    IF (@ExecutionResult <> 0)
    BEGIN
          EXEC sp_OAGetErrorInfo @hnd, @errorSource OUTPUT, @errorDescription OUTPUT
          SELECT @errorSource, @errorDescription
    END
     
    EXEC @ExecutionResult = sp_OAMethod @hnd, 'getSum', @result OUTPUT, 10, 20
    IF (@ExecutionResult <> 0)
    BEGIN
          EXEC sp_OAGetErrorInfo @hnd, @errorSource OUTPUT, @errorDescription OUTPUT
          SELECT @errorSource, @errorDescription
    END
     
    EXEC @ExecutionResult = sp_OADestroy @hnd
    IF (@ExecutionResult <> 0)
    BEGIN
          EXEC sp_OAGetErrorInfo @hnd, @errorSource OUTPUT, @errorDescription OUTPUT
     
          SELECT @errorSource, @errorDescription
    END
     
    SELECT @result

    More MS SQL Server Articles
    More By Jagadish Chaterjee


       · Databases can be difficult to deal with; I hope you found this article on developing...
     

    MS SQL SERVER ARTICLES

    - Windows Server 2008 as a Workstation OS
    - An Overview of Windows Server 2008 R2
    - LINQ to MySQL, Oracle and PostgreSQL Provide...
    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek