Database Explorer and Code Generator - Stored Procedures and SqlConnectionStringBuilder

So my Database Explorer and Code Generator now displays database views separate from database tables and shows stored procedures in the database, too.  This is all pretty trivial, but fun to build.  The image below shows the stored procedures from the Northwind Database.

 

 

Code Generation with Stored Procedures

If you right click on a stored procedure it generates a couple of useful code snippets:

  • A SQL Command with parameters for calling the stored procedure from your code
  • A class method that includes the above along with proper arguments and usage of DAAB 2.0.

This was quick to implement since the code was built already, because when your right click on a table I have it already generating 1) Active Data Record, 2) Table Data Gateway, and 3) Data Access Object using DAAB 2.0.  All I had to do was a bit of refactoring and specify ComandType.StoredProcedure as opposed to CommandType.Text.

I downloaded the Enterprise Library for .NET 2.0 December Update to investigate generating code for use with it.

 

SqlConnectionStringBuilder and Builder Design Pattern

Awhile back I was talking about the Builder Design Pattern, which I still need to complete:

I mentioned how the SqlConnectionStringBuilder Class allows you to build a connection string using the Builder Design Pattern.

What is useful about this SqlConnectionStringBuilder Class is that it will also accept a connection string as a constructor argument and breaks the connectionstring into its various parts:

 

SqlConnectionStringBuilder builder =
    new SqlConnectionStringBuilder(connectionString);
    
string initialCatalog = builder.InitialCatalog;
string datasource = builder.DataSource;

// ...

 

The SqlConnectionStringBuilder Class is a big help to me in my Database Explorer and Code Generator when allowing the user to either 1) navigate to the database of choice step-by-step in the New Project dialog or 2) specify a connection string.

Fun stuff.  Now back to work.

Posted by: David Hayden

 

posted on Tuesday, December 06, 2005 1:34 PM

Main

News

Green Tea

.NET Development

Enterprise Library

Patterns & Practices