Monday, March 31, 2008

T-SQL Drop Stored Procs - NetTiers version via cursor

After generating all CRUD procs with several different naming prefixes, my database was looking messy. So I knew what I wanted to produce but I needed to get rid of all these other procs. So how to quickly drop all the procs. Wayne said he had a codesmith template for it but I couldn't wait. I google'd and found another person that had the same problem after a heavy CodeSmith NetTiers session. His method was not too different from my post from yesterday. I did my final gen of procs via NetTiers but instead of going into the database, sent them to a file. I opened the file to find the following code which should have been both obvious in that NetTiers would need it and where I should look for it:


DECLARE @procedureName SYSNAME


SELECT name FROM sysobjects WHERE type = 'P' AND objectproperty(id, 'IsMSShipped') = 0

AND name LIKE 'NetTiers_%' AND name NOT LIKE 'WW_{0}_%'


FETCH NEXT FROM c INTO @procedureName



EXEC('DROP PROC ' + @procedureName)

FETCH NEXT FROM c INTO @procedureName






Sunday, March 30, 2008

T-SQL Drop Stored Procs - query window

In Sql server query window, execute query that selects all stored procedures with the prefix you want (such as procedures that start with 'cust'):

SELECT 'DROP PROCEDURE ' + Name FROM sys.objects

WHERE type in (N'P', N'PC')

and name like 'cust_%'


Right-click the query window and set results to text. This gives you a results window with a single column of drop prodecures. Select all the text, copy to a new query window and execute.

Saturday, March 29, 2008

CodeSmith NetTiers Best Practices

After using NetTiers for a couple of weeks now, here are some suggestions for usage:

1) Use NetTiers like any third party library. Build it and include the libraries. Do not alter code inside generated libraries unless mission critical. I also use the Microsoft.Patterns library. They ship the code but I don't alter it, I just use the built libraries. 

2) Prefix the library namespace with NetTiers so that the generated libraries look like NetTiers.Entities, NetTiers.Data, etc.

3) If you use NetTiers to generate your CRUD, set the ProcedurePrefix value to NetTiers_. When you are looking through a million procs, it easier to pass a whole section based on alphabetical sorting. If you use AspNet Membership, you will be accustomed to this naming schema as those procs are prefixed with aspnet_

4) If you create your own procs, prefix those procs to something that you won't confuse with any other library's procs, such as 'cust' for custom. Of cource, IncludeCustoms is set to true and CustomProcedureStartsWith should be set to 'cust_{0}_' so that a table name of Profile should have a custom proc of cust_Profile_SelectAll.

5) While still getting your template settings figured out:

  • Don't set ExecuteSQL to true until you have tested your generated SQL and looked through what was created.
  • Set LaunchVisualStudio to true and save yourself a few clicks.
  • Set ViewReport to false. You don't need another browser to open while you are still figuring out your templates.

6) Build the Web Service and the Admin site. Even if you don't plan to use AJAX or you have your own admin pages already built, these are just more examples of NetTiers code usage. Then when you need a data backdoor or quick AJAX, you are that much closer.

7) NetTiers documentation suggests using DeepLoad to get to a related table via FK. I can see how this would be used in their example of list of Orders in a grid and you also want to display the Customer's Name in the grid. What if you had a table of ProfileItems and a table of UserProfileItems and you wanted a list of all the ProfileItems in a grid with this user's settings? With the NetTiers usual get based on FK from either table, you won't get the grid I want (right?). So in that case, I'll create a custom proc with the proper bind.

Friday, March 28, 2008

CodeSmith NetTiers discovery of a custom stored procedure

I have a table with two FKs. NetTiers creates a stored proc for the PK as well as a stored proc for each FK however it doesn't create a stored proc that uses both FKs as the IN params. So I need to create this in a way that NetTiers can discover it and build the code objects to support it.

First I have to create the stored proc with a discoverable name. This requires several settings in the NetTiers template. First, that I want custom stored procs discovered so IncludeCustoms=true. Second, I want any stored procs to have a naming prefix so ProcedurePrefix=usp. Third, I need to handle the actual name of the stored proc. NetTiers uses discovery based on a template where the zeroth parm is the table name and the first parm is the Procedure Prefix so CustomProcedureStartsWith={1}_cust_{0}_. The remainder of the stored proc name is irrelevant but what is returned is very important. I usually return all columns which is NetTiers default object handling. If I choose not to include all columns, I would have to deal with an IDataReader or a DataSet.

If all the other stored procs and NetTiers code has been generated and you only new a few stored procs to be discovered, make sure to set ExecuteSQL=false and SourceTables=(only immediate tables.)

Once you generate your objects, you can verify the stored proc was discovered by looking in the Data layer in the base directory for the TableNameProviderBase.generatedCore.cs in the Custom Methods region.

Thursday, March 27, 2008

How do you GridView?

I've been stuck in build hell for a week but now back to code. I want data that would normally be a JOIN between two tables. It's a join between ProfileProperties and UserProfileValues. But since I'm using NetTiers for my middle tier and I just want to get going, I'm writing a subpar GridView. The first column is pulled from a select of all profile properties provided by my ProfileDataSourceObject given to me by NetTiers. The second column is a function with a param of the profile property. The function grabs the user from the context and the profile property from the param, then determines what (if any) value has been set. This is not how I should do things. And since I usually don't do it this way, I'm sort of having to relearn some aspx syntax on how to do this.

I much prefer to have SQL return this data and just format it in the GridView. SQL doesn't change everytime Microsoft releases a new version of Visual Studio.

How would you do this?


Wednesday, March 26, 2008

More NetTiers configuration

Building Separately

Building the NetTiers projects are getting tedious inside my main web app solution. I'm now building them separately and just moving into my main solution as references to each project. While I'm making so many database design changes, that is the best option. When the table designs and relationships are in place, I may move the .NetTiers projects back into my main solution.

Table Standards

One of my tables had the 'name' column as the last column as opposed to the column immediately following all the id,pk,fk columns. NetTiers decided only the next column after the id,pk,fk must be the most meaningful. It used this column which was not the name column but some non-determining column as the value for drop down lists in it's web admin site. So for everytable who had this table as a fk, this non-determining column populated as drop down list. So I had to change that in the database then regenerate the NetTiers projects.

NetTiers Admin site not converting to web app

This seems to be a common problem. One googled answer said to rebuild the project twice in a row and the conversion would succeed. I don't know what I did but when I selected the Admin folder and choose convert, I got a bogus error. Then I converted each file individually, and it succeeded.

NetTiers Admin Quick Look

The NetTiers CodeSmith templates create an admin site  (if you configure it to). Here is what a couple of the pages look like:

Monday, March 24, 2008

ID ten T error (ID10T): Check the data

I finally got NetTiers up and running and wanted to see my data. I choose the last data table I designed. I just spent an hour trying to use NetTiers to see my data with their version of a DataSource for that table. I finally figured out the table has nothing to see. Ugh!!!


The last hiccups were web.config issues. Easily found answer on google.


So NetTiers templates are configured. NetTiers projects are integrated into my solution with several other projects. Everything builds. I can call the highest level web and data NetTiers objects. Now time to check in to source control. I'm checking in entire NetTiers template tree, all generated files from the templates, and all changes to my web app so that I can use NetTiers.

I don't build directly into my project tree so I have to copy the generated files over. This is a failsafe for now that I expect to eventually remove.

I already have a change to a table to make so I'll figure out how I want that process to go.


Source Safe Control from Visual Studio 2005

Apparently, Source Safe and Visual Studio have to have the projects as sibling nodes both on the hard drive and in source safe. The source safe names must match the Visual Studio project names. So after dinking with both to try to get them to talk to each other, I scraped my current visual studio node and reorganized my hard drive directories so that all projects are siblings and the solution files are in the parent directory.

Then I tried to tie Visual Studio to Source Safe by hand. Since it still didn't work, I renamed my visual studio parent node just to save it instead of deleting. Then I had the Visual Studio solution add all the projects to source safe. This is definitely not the recommended method but everything is still small.

One of these days, I just code. And code. And code.



Saturday, March 22, 2008

NetTiers Template Integration with Existing Solution

I've been working for two hours to get my existing NetTiers CodeSmith Template to generate the files the way I need them. The NetTiers template gets 90% there out of the box but the template tips for each line item are sometimes obsure or require another lineitem to be TRUE. Then there is a fair bit of user error such as what to name the libraries created by the template, the directory they should be sent to. One error right out of the box is the LibraryPath value. It's inconviently stuffed in the Advanced CRUD section and just says Reference. After the projects try to build but fail but to the reference libraries not found, I figured out what was going on.

NetTiers generates the web service and client pieces which I keep in the template but don't use.

No I'm working on making sure my project library which includes all the libraries built by NetTiers CodeSmith has the right hierarchy in terms of having functions where I would expect them to be.

I'm sure at some point I'll actually get to the point where I call some of these great new classes.

Friday, March 21, 2008

So You Want Your Own Business Website (SYWYOW): Where do you begin?

I have met several local business people that either want or need a business web site beyond a brochure site. This post is aimed at those people so this category is not for techies per say but is a forum to discuss the client side of the business.

Let's assume the web client needs to be able to

  • Introduce Company and People
  • Provide contact information and previous work bonafides
  • Provider specific and detailed information about the products or services they provide to local clientele
  • Provide access so that company person can manage site's information
  • Show enough design thought that customers don't think someone's eight-year old just learned HTML

So why pay a programmer (like me) upwards of $60/hour for this. This is basically a web site builder. You can buy this for around $10/month with more features and designs than you need. What skills do you need to be able to do this yourself?

  • Able to use a computer browser
  • Able to type/edit on keyboard
  • Able to read and respond to email

The downside of this, and it's huge for any small business owner, is that now there is one more thing you need to take care of. Is it worth it to hire another person to do your typing when there are changes? Sure, but that's not a web programmer or web designer. That's usually called a secretary and they are inexpensive compared to a programmer. Always ask yourself are you hiring the right person for the job.

Thursday, March 20, 2008

Dina's Pet Project Summary

So where am I with my Pet Project?


  • the domain name(several really) purchased
  • domain names linked to the web server
  • email entries set up
  • new virtual development server (Thanks Wayne)
  • VS2005 web project with a middle layer library
  • SQL Server database for project
  • SQL Server database for bugtracker/issue mgmt
  • CodeSmith
  • .NetTier with a template close to what I need
  • basic but ugly functionality
  • using Microsoft Membership, Roles (Profiles are home grown)