<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Databases</title>
        <link>http://bchavez.bitarmory.com/category/1.aspx</link>
        <description>Posts about databases</description>
        <language>en-US</language>
        <copyright>Brian Chavez</copyright>
        <managingEditor>bchavez@bitarmory.com</managingEditor>
        <generator>Subtext Version 1.9.5.176</generator>
        <item>
            <title>NHibernate - null id in entry (don't flush the Session after an exception occurs)</title>
            <link>http://bchavez.bitarmory.com/archive/2007/11/14/nhibernate---null-id-in-entry-dont-flush-the-session.aspx</link>
            <description>&lt;p&gt;&lt;img style="margin: 10px" height="52" alt="image" src="http://bchavez.bitarmory.com/images/bchavez_bitarmory_com/WindowsLiveWriter/NHibernatenullidinentrydontflushtheSessi_BC87/image_308de7db-c740-4525-b003-2ded000b06d0.png" width="230" align="left" border="0" /&gt;I ran into this issue today when trying to persist one of my objects.  The cause of the problem was interesting.  I was trying to save an object when a property/columns in the table had a unique constraint.  As a result, the object that I was trying to persist would not persist simply because the object's property it failed to meet the unique constraint.&lt;/p&gt; &lt;p&gt;As a result, a call to Save() on the object failed and the ID on the object I was trying to save was not set, but NHibernate still processed the object and associated it with its persistence mechanism leaving it in a "semi-persistent" state with the NHibernate persistence manager (ie: NHibernate now knows about the object you tried to save and it SHOULD have fully evicted the object from its persistence manager because the save failed, but it didn't).&lt;/p&gt; &lt;p&gt;When an HTTP request finishes on my ASP.NET application, I flush and close all NHibernate session objects at the time the request is done.  And as a result, when the HTTP request finished, NHibernate attempted to flush the jacked up "semi-persistent" object (an object who's ID was null) and ultimately generating the error above.&lt;/p&gt; &lt;p&gt;So, the solution that I implemented was to wrap the Save() in a try{} catch{} statement, and if the save failed, immediately close and shutdown the session, handle the error/exception.  Then, check if Session.IsOpen when the HTTP request finishes.&lt;/p&gt; &lt;p&gt;Hope that helps, &lt;img alt="confused0081.gif" src="http://bchavez.bitarmory.com/Images/emotions/confused0081.gif" /&gt;&lt;/p&gt; &lt;p&gt;Brian Chavez&lt;/p&gt;&lt;img src="http://bchavez.bitarmory.com/aggbug/37.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brian Chavez</dc:creator>
            <guid>http://bchavez.bitarmory.com/archive/2007/11/14/nhibernate---null-id-in-entry-dont-flush-the-session.aspx</guid>
            <pubDate>Wed, 14 Nov 2007 21:41:11 GMT</pubDate>
            <wfw:comment>http://bchavez.bitarmory.com/comments/37.aspx</wfw:comment>
            <comments>http://bchavez.bitarmory.com/archive/2007/11/14/nhibernate---null-id-in-entry-dont-flush-the-session.aspx#feedback</comments>
            <slash:comments>5</slash:comments>
            <wfw:commentRss>http://bchavez.bitarmory.com/comments/commentRss/37.aspx</wfw:commentRss>
            <trackback:ping>http://bchavez.bitarmory.com/services/trackbacks/37.aspx</trackback:ping>
        </item>
        <item>
            <title>WMI Provider Error - Access Denied - TDSSNIClient initialization failed with error 0x5</title>
            <link>http://bchavez.bitarmory.com/archive/2007/11/06/wmi-provider-error---access-denied---tdssniclient-initialization-failed.aspx</link>
            <description>&lt;p&gt;&lt;img height="428" alt="image" src="http://bchavez.bitarmory.com/images/bchavez_bitarmory_com/WindowsLiveWriter/WMIProviderErrorAccessDeniedTDSSNIClient_8752/image_5a9f40fc-4d40-43fb-804e-1773321ded5e.png" width="408" align="left" border="0" /&gt;I got an interesting error while trying to change the log on service account for SQL server.  I got a "WMI Provider Error" and a bunch of errors in the Windows Event Log.&lt;/p&gt; &lt;p&gt;Simple solution:&lt;/p&gt; &lt;p&gt;Restart.&lt;/p&gt; &lt;p&gt;The problem is simply, a Named Pipe issue.  Restarting re-creates the Named Pipe under the correct log on account.&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;If the restart fails, and you're still having problems connecting to SQL Server Remotely, try the following:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Set the log on account permissions on:&lt;br /&gt;&lt;br /&gt;C:\Program Files\Microsoft SQL Server&lt;br /&gt;C:\DATA DIRECTORY&lt;br /&gt;&lt;br /&gt;for the log on account.  You'll need to set "Full Control" permissions and make sure that you re-apply the rule to all children by clicking on the directory properties&amp;gt;Security&amp;gt;Advanced&amp;gt;Permissions&amp;gt;"Replace permission entries on all child objects..."&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Hope that helps.&lt;/p&gt;&lt;img src="http://bchavez.bitarmory.com/aggbug/34.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brian Chavez</dc:creator>
            <guid>http://bchavez.bitarmory.com/archive/2007/11/06/wmi-provider-error---access-denied---tdssniclient-initialization-failed.aspx</guid>
            <pubDate>Tue, 06 Nov 2007 18:44:42 GMT</pubDate>
            <wfw:comment>http://bchavez.bitarmory.com/comments/34.aspx</wfw:comment>
            <comments>http://bchavez.bitarmory.com/archive/2007/11/06/wmi-provider-error---access-denied---tdssniclient-initialization-failed.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://bchavez.bitarmory.com/comments/commentRss/34.aspx</wfw:commentRss>
            <trackback:ping>http://bchavez.bitarmory.com/services/trackbacks/34.aspx</trackback:ping>
        </item>
        <item>
            <title>General Database Design Guidelines and Naming Conventions</title>
            <link>http://bchavez.bitarmory.com/archive/2007/08/15/general-database-design-guidelines-and-naming-conventions.aspx</link>
            <description>&lt;p&gt;Here are some helpful tips on database naming conventions. Consistency, readability, maintainability, and extensibility are some of the most important factors when designing new databases. In this blog I'll go over some conventions I use to keep myself consistent. If you have any conventions you follow or ways to improve these conventions, let me know. :) 
&lt;/p&gt;&lt;h2&gt;Entity Class Naming 
&lt;/h2&gt;&lt;p&gt;The name of our entity classes should be in the singular form, for example &lt;strong&gt;Account&lt;/strong&gt;, &lt;strong&gt;Customer&lt;/strong&gt;, or &lt;strong&gt;User&lt;/strong&gt; (for a user accounts table). Plural names (such as Accounts, Orders, and Order Details) aren't good candidate for entity names because 1) plural names don't grammatically fit well when reading relationships that are self-referencing and one-to-one 2) it reduces the readability of SQL statements when fully qualified names the WHERE clause. To Illustrate: 
&lt;/p&gt;&lt;p&gt;&lt;span style="color:green; font-family:Courier New; font-size:10pt"&gt;/* Using singular form */&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;SELECT&lt;/span&gt;
			&lt;span style="color:gray"&gt;*&lt;/span&gt;
			&lt;span style="color:blue"&gt;FROM&lt;/span&gt; Account &lt;span style="color:blue"&gt;WHERE&lt;/span&gt; Account&lt;span style="color:gray"&gt;.&lt;/span&gt;ID &lt;span style="color:gray"&gt;=&lt;/span&gt; 1&lt;span style="color:gray"&gt;;&lt;/span&gt;&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt; &lt;span style="color:red; font-family:Courier New; font-size:10pt"&gt;/* Using plural form */&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;SELECT&lt;/span&gt;
			&lt;span style="color:gray"&gt;*&lt;/span&gt;
			&lt;span style="color:blue"&gt;FROM&lt;/span&gt; Accounts &lt;span style="color:blue"&gt;WHERE&lt;/span&gt; Accounts&lt;span style="color:gray"&gt;.&lt;/span&gt;ID &lt;span style="color:gray"&gt;=&lt;/span&gt; 1&lt;span style="color:gray"&gt;; &lt;/span&gt;&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;     
 &lt;/p&gt;&lt;p&gt;If you ask me, the singular form reads much better in the &lt;span style="color:blue; font-family:Courier New; font-size:10pt"&gt;WHERE&lt;/span&gt; clause, but the plural form performs better in the &lt;span style="color:blue; font-family:Courier New; font-size:10pt"&gt;FROM&lt;/span&gt; clause. When creating complex SQL queries, readability in the &lt;span style="color:blue; font-family:Courier New; font-size:10pt"&gt;WHERE&lt;/span&gt; clause tends to outweigh the benefits of readability in the &lt;span style="color:blue; font-family:Courier New; font-size:10pt"&gt;FROM&lt;/span&gt; clause. This is why singular table names are generally better. Furthermore, the name of the entity should be representative of a single row in the table. Names like History, Schedule, and Table are not descriptive enough. 
&lt;/p&gt;&lt;p&gt;For certain types of entities, special keywords should be contained in the naming of the entity. Below is a list of special entities and associated key words that should be considered a part of the naming scheme. 
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Tracking History: History, Historical, Event 
&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;       
 &lt;/p&gt;&lt;h2&gt;Attribute Naming 
&lt;/h2&gt;&lt;p&gt;Below is a small list of naming guidelines for naming columns based on the type of data they hold. 
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Identifiers: Number (or No), Code, Identifier (or Id), Tie-Breaker 
&lt;/li&gt;&lt;li&gt;Categories: Type, Method, Status, Reason 
&lt;/li&gt;&lt;li&gt;Counts: Count 
&lt;/li&gt;&lt;li&gt;Dimensions: Length, Width, Height, Weight 
&lt;/li&gt;&lt;li&gt;Amounts: Amount, Price, Balance 
&lt;/li&gt;&lt;li&gt;Factors: Rate, Concentration, Ratio, Percentage 
&lt;/li&gt;&lt;li&gt;Specific Time Points: Timestamp, DateTime, Date, Month, Year 
&lt;/li&gt;&lt;li&gt;Recurrent Time Points: TimeOfDay, DayOfWeek, DayOfMonth, DayOfYear, MonthOfYear 
&lt;/li&gt;&lt;li&gt;Intervals: Duration, Period 
&lt;/li&gt;&lt;li&gt;Positions: Point, LineSegment, Polygon 
&lt;/li&gt;&lt;li&gt;Texts: Name, Description, Comment, Instructions 
&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Try to avoid abbreviations; it may likely confuse business people using the database. 
&lt;/p&gt;&lt;h2&gt;Natural Keys vs Surrogate Keys 
&lt;/h2&gt;&lt;p&gt;&lt;img src="http://bchavez.bitarmory.com/Upload/081507_0718_GeneralData1.png" alt="" /&gt;
	&lt;/p&gt;&lt;p&gt;When choosing the primary key for a table, often in designs, natural keys occur in the business problem. For example, if we're modeling a Person table in our database we might be inclined to use the Social Security number (a natural key) of a person as the primary key in the Person table. This isn't a bad design, since everyone in the US should have a Social Security number; however, keying the Person table with a Social Security number as the primary key doesn't lead to an extensible design. What happens if the system and database we're designing for needs to handle people who are not US citizens or people who don't have a Social Security number? As you can see, using a Surrogate Key named &lt;strong&gt;PersonId&lt;/strong&gt; with an identity constraint as our primary key is a much better extensible database table design than using a natural key. In most cases, even if the natural key is truly unique, I would still use a Surrogate Key. 
&lt;/p&gt;&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;That's all for now! If I come think of some more, I'll add them to this blog post later. :) Keep in mind there is no "best practice" because any best practice can be turned into a worst practice if the situation changes. The point is the schema design of every database should be well thought out. Being consistent in your designs help leads designs to be readable and maintainable. Extensibility leads your designs to be changed and refactored when business processes change.&lt;/p&gt;&lt;img src="http://bchavez.bitarmory.com/aggbug/8.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brian Chavez</dc:creator>
            <guid>http://bchavez.bitarmory.com/archive/2007/08/15/general-database-design-guidelines-and-naming-conventions.aspx</guid>
            <pubDate>Wed, 15 Aug 2007 14:18:35 GMT</pubDate>
            <wfw:comment>http://bchavez.bitarmory.com/comments/8.aspx</wfw:comment>
            <comments>http://bchavez.bitarmory.com/archive/2007/08/15/general-database-design-guidelines-and-naming-conventions.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://bchavez.bitarmory.com/comments/commentRss/8.aspx</wfw:commentRss>
            <trackback:ping>http://bchavez.bitarmory.com/services/trackbacks/8.aspx</trackback:ping>
        </item>
    </channel>
</rss>