Thursday, March 27, 2008

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 9:00:03 PM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  | 
 Wednesday, March 26, 2008

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 7:30:31 PM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  | 
 Tuesday, March 25, 2008

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:


Tuesday, March 25, 2008 7:30:18 PM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  | 
 Monday, March 24, 2008

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.

 

 

Monday, March 24, 2008 8:16:21 AM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  | 
 Sunday, March 23, 2008

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.

 

Sunday, March 23, 2008 7:29:15 PM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  | 
 Friday, March 21, 2008

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 8:26:32 PM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  | 
 Thursday, March 20, 2008

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.

Dina | SYWYOW
Thursday, March 20, 2008 6:46:27 PM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  | 
 Wednesday, March 19, 2008

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)
Wednesday, March 19, 2008 6:17:02 PM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  | 
 Tuesday, February 26, 2008

Here is a little code that will create a class that you can use with Enterprise Library caching.  Basically it allows you to define a WHERE clause where any object in that WHERE clause changes (across a single table) then the cache will expire the object in the cache.  Think of it as a way to store a List<> of object that represent rows in a table in the cache and be able to detect if any row changes so that you can drop the cached list.  LastUpdate is a timestamp column that needs to be on every row.  This works since timestamp column type is always incremented by one, which means that SELECT MAX(LastUpdate) will tell you the maximum change across all rows.

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Caching.Properties;

namespace ERS.Base
{
    /// <summary>
    /// 
    /// </summary>
    public class TableSqlDependency : ICacheItemExpiration
    {
        String _tableName = String.Empty;
        String _connectionString = String.Empty;
        String _where = String.Empty;
        Byte[] _lastUpdate = null;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="tableName"></param>
        public TableSqlDependency(String connectionString, String tableName)
        {
            _connectionString = connectionString;
            _tableName = tableName;
        }

        public TableSqlDependency(String connectionString,
            String tableName,
            String where)
        {
            _connectionString = connectionString;
            _tableName = tableName;
            _where = where;
        }

        // Summary:
        //     Specifies if item has expired or not.
        //
        // Returns:
        //     Returns true if the item has expired, otherwise false.
        public bool HasExpired()
        {
            Byte[] lastUpdate = LastUpdate;

            if ((lastUpdate == null) && (_lastUpdate != null))
                return (true);

            if ((lastUpdate != null) && (_lastUpdate == null))
                return (true);

            if ((lastUpdate == null) && (_lastUpdate == null))
                return (false);

            if (lastUpdate.Length != _lastUpdate.Length)
                return (true);

            for (int i = 0; i < lastUpdate.Length; i++)
                if (lastUpdate[i] != _lastUpdate[i])
                    return (true);

            return (false);
        }

        private Byte[] LastUpdate
        {
            get
            {
                Byte[] lastUpdate = null;

                using (SqlConnection sqlConnection =
                    new SqlConnection(
                        ConfigurationManager.ConnectionStrings[_connectionString]
                        .ConnectionString))
                {
                    String sql = String.Empty;

                    if (!String.IsNullOrEmpty(_where))
                        sql = String.Format(
                            "SELECT MAX([LastUpdate]) 'Max' FROM [{0}] WHERE {1}",
                            _tableName, _where);
                    else
                        sql = String.Format(
                            "SELECT MAX([LastUpdate]) 'Max' FROM [{0}]",
                            _tableName);

                    using (SqlCommand sqlCommand =
                        new SqlCommand(sql, sqlConnection))
                    {
                        sqlConnection.Open();

                        sqlCommand.CommandType = CommandType.Text;

                        using (SqlDataReader sqlDataReader =
                            sqlCommand.ExecuteReader())
                        {
                            if (!sqlDataReader.HasRows)
                                lastUpdate = null;

                            sqlDataReader.Read();

                            lastUpdate = (Byte[])sqlDataReader["Max"];
                        }
                    }
                }

                return (lastUpdate);
            }
        }

        //
        // Summary:
        //     Called to give the instance the opportunity to
        //        initialize itself from information
        //     contained in the CacheItem.
        //
        // Parameters:
        //   owningCacheItem:
        //     CacheItem that owns this expiration object
        public void Initialize(CacheItem owningCacheItem)
        {
            _lastUpdate = LastUpdate;
        }

        //
        // Summary:
        //     Called to tell the expiration that the CacheItem to which
        //        this expiration
        //     belongs has been touched by the user
        public void Notify()
        {
        }
    }
}

{6230289B-5BEE-409e-932A-2F01FA407A92}

.net | C# | T-SQL | Wayne
Tuesday, February 26, 2008 10:44:49 AM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [0]  |