Geek Noise
Rants, rambles, news and notes by Peter Provost
07

SP/Invoke - Stored Proc Wrapper Code Generator

Wednesday, 7 May 2003 08:42 by Peter Provost

This looks very cool. It generates nice little OO classes for your Stored Procedures. Here are some comments from their website:

SP/Invoke was our submission to the 'Spend a Day With .NET' contest. It is a small tool which generates code to simplify the invocation of SQL Server T-SQL Stored Procedures.

For example, for the following stored procedure (taken from the Northwind SQL Server example database) ...

create procedure CustOrderHist @CustomerID nchar(5)
as
  select ProductName, Total=sum(Quantity)
  from Products P, [Order Details] OD, Orders O, Customers C
  where C.CustomerID = @CustomerID
  and C.CustomerID = O.CustomerID and O.OrderID = OD.OrderID and OD.ProductID = P.ProductID
  group by ProductName

... SP/Invoke generates code allowing you to invoke the stored procedure using ...

SqlConnection conn = new SqlConnection("...");
conn.Open();

CustOrderHist.Result r = CustOrderHist.Invoke(conn, "OTTIK");

if (r.ReturnValue != 0)
  return;

foreach (CustOrderHist.Row order in r)
{
  Console.WriteLine(order.ProductName);
  Console.WriteLine(order.Total);
}

SP/Invoke generates code using the CodeDOM and then compiles it to an assembly which can be used from any VS.NET project. C# code can optionally be generated for direct inclusion into a C# project.

The UI functions as a VS.NET Add-In and can be accessed from the IDE's 'Tools' menu.

More thanks to Mike from Larkware News for this link.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Technology
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed