Twin Cities Code Camp 2007

On October 27th, 2007 the 3rd anual Twin Cities Code Camp will be taking place. I would definitely recommend attending this event for anyone located in the twin cities area! I’ve been to the last two code camps and thought it was a fun way to meet new people and learn about new things. They also have a pretty good list of give aways and it’s free! Hard to beat that.
Well this year I’ll not only be attending but I’ll be giving a presentation about NBusiness, so if anyone is interested in learning more or talking to me in person this is a perfect opportunity. I haven’t worked out my slides or my demo yet but I’m thinking I might use this very blog as an example of how to use NBusiness in the real world.
If anyone has something specific they like to hear more about let me know and I’ll try to focus on it. There should be some time for questions in general as well. I’d love to see this attract a little more attention and get a few more people interested in trying it out.
So if you’re not sure what you’re doing on Oct. 27th, navigate to the TWCC website and register now!

NBusiness v2.0.1 Released

This release fixes a few issues that were reported to me related to sibling relationships, the schema updater and the schema updater menu items. Let me know if you still have problems with the menu items because I can’t seem to duplicate the issue on my development machine or test VPC. I have done a few things that I think might help but it’s really hard to say 100%.
Anyway, with the sibling relationships I realized that there was no guarantee as to the order of the relationships. Meaning if you had Person and Address entities, in order to create the intermediate tables in the sql scripts template, the template would either name it PeopleAddresses or AddressesPeople… depending on the order of the entities. With no guarantee as to the order there was no guarantee what the table would be named. This would cause custom scripts to blow up or running the schema updater on a database with a table of the other name would result in the database not being rebuilt properly either. So now the template will order all of the entities alphabetically before attempting to create sibling related scripts, which will guarantee that all of the tables will be predictably named. In the example above you should alwasy get AddressesPeople from now on.

Hosted Website Installations

 
After working with a hosted website for a little while it’s easy to come to the conclusion that deployment can be a real pain in the neck. Large 3rd party web hosts such as Go Daddy (which is who hosts this site currently) certainly do not give you an easy way to migrate certain changes to your website. If your website is simple HTML and you’re doing some minor incremental changes from time to time then it’s not really a big deal but when it comes to a dynamic, datadrive website site, even one as simple as this one, deployment is painful.
 
The problem comes from not having direct access to the database. The database is securely hidden behind a firewall but as annoying as this is you wouldn’t really want it any other way. VPN access would be nice but it’s understandable why this isn’t available. As a solution they typically give you access to some web front end to your database and while this is better than nothing, frankly, these applications usually suck. I’ve found that not only are they usually pretty slow and visually confusing but they are typically not compatible with the same transactional scripts that you would run in your own development environment.
 
[Example of GoDaddy’s Web DB Frontend]
 
So this is the cruxt of the problem. The first time I went to deploy my site I had a rather long script full of table creates and primary keys and foreign keys and lengthy stored procedures only to attempt to run it in this web front end and have it fail miserably. I then removed the GO statements from my srcript, since it didn’t seem to like them, and I ended up with a spattering of tables and sprocs and had to go through and manually delete a lot of things. It was very painful and tiresome.
 
So after doing this about once you quickly realize there must be a better solution. The sample code posted with this blog is an example of how to make a reusable hosted website installation package. It’s pretty simple but that’s usually the best way to do things. You’ll probably want to refactor the code in this example to fit in with your project but here is the basic idea behind everything.
 
First off, you have your installer classes. You have an abstract InstallVersion class which is essentially a collection of InstallActions along with some version information. You will create one of these classes for each version you roll out to your server. It’s probably a good idea (and not much work) to keep all of your scripts and install version classes along the way rather than just upgrading the same one over and over. The reason for this is just in case you need to rebuild a database due to a migration, a crash or perhaps a new deployment without any of the old data. In those cases you may be stuck with nothing but ALTER TABLEs at the end and you’ll need to install everything from step 1 to 100 to get back to where you want to be.
 
Your first script will have mostly CREATE statments (probably from the complete.sql generated by NBusiness) but each subsequent one will have ALTERS as well as other things needed to massage your data into the new formats.
 
There are a couple of already made InstallActions created for running sql scripts but you can imagine all sorts of other actions such as ones that delete files, create/edit/delete Users and Roles if you’re using ASP.NET Role/Membership providers. You could also imagine some actions that might do something like send an email to make sure you have your sites SMTP configurations setup correctly.
 
To configure your installer simply add a custom install configuration section to your web.config. Check out the sample to see how to do this. Then you create a page in a secure directory (accessible only by admins) and add the Installer control to that page. The installer control will look at your configuration settings and load your install classes and ask them if they have been installed or not. If they have not then buttons will be created for that version, ready for you to execute the install actions. We’re using NBusiness here to keep track of installed versions but you could just as easily come up with a scheme for saving files or something. Just remember that you don’t always have write permissions in medium trust like you do in your full trust development environement so always be sure to add the <trust level=”Medium” /> to your web.config so you can have a development environment with the same restrictions!
 
This is just one way to accomplish these goals. I’ve tried to add some semblance of a pattern and reuse to this problem and while this isn’t perfect (notably a lack of transactions across InstallActions) it’s MUCH better than nothing while still remaining pretty simple.
 
Enjoy!

NBusiness v2.0 Released!

After working for over a year on this project I have finally achieved my original goals! It’s been a long and intense year of coding for me and I’ve loved every second of it. I still have some major features ahead of me and (no doubt) lots of debugging still but I have managed to produce something that I feel is pretty good quality and will be beneficial to everyone that uses it.

Download NBusiness v2.0 here.

Of course there are still some known issues to work out and plenty of room for improvement in the entity authoring experience, especially as it relates to intellisense in the C#/VB code beside. I’m not sure how to fix this though I have looked into it some already but I can say that it’s a top priority here.

When releasing this build I had to decide whether or not I should release an “imperfect” build or delay it longer but fix all of the issues I was seeing. If this was a commercial project I probably would have tried to work out more of the issues first but since it is (mostly) only me I felt it wasn’t worth delaying things much longer, since I can only do so much so fast. However, most of the known issues are annoyances and not critical show stoppers anyway. Despite these few remaining problems I’m very happy with this release and find myself wanting to use it with any new project. In fact it’s hard to imagine doing it any other way at this point!

Here is a screen shot of NBusiness integrated into Visual Studio (click to view fullsize):

I’m going to try to make some screen casts pretty soon too. I have never really done that before but I think a couple simple screen casts would be pretty helpful for people.

And please everyone, let’s make use of the forums and work items on codeplex!

Mapping Sql Types to .NET Types

I bet there is an article out there somewhere that tells you exactly what .NET Types to use with the corresponding SQL column types but I couldn’t find it anywhere. After scanning for a few minutes I decided to just write something up that tells me definitively what Type to use.
In this case I needed it because I had a bug in NBusiness whith the mapping to the double. After changing the Type a few times I couldn’t figure out what Type to actually map to a double. So I created a table that has one column of each type and I used a simple SqlDataReader to figure out the .NET Type of the field.
I created a simple type mapper just to show me what I wanted. And here are the results:
Sql Type .NET Type
bigint long
binary byte[]
bit bool
char string
datetime DateTime
decimal decimal
float double
int int
money decimal
nchar string
ntext string
nvarchar string
real single
smalldatetime DateTime
smallint short
smallmoney decimal
sql_variant object
text string
tinestamp byte[]
tinyint byte
uniqueidentifier Guid
varbinary byte[]
xml string