Post Archives
Archive for the ‘Programming’ Category

Windows could not start the SQL Server on Local Computer Error Code 3417

December 21st, 2011 5 comments

I havn’t been using SQL Server on my development machine for a while so to speed things up I changed the service startup to manual.  Recently I’ve needed SQL Server but when I tried to start the service I got an error saying Windows could not start the SQL Server on Local Computer with the Error Code 3417.  This was rather odd, so I started doing some google searched but with no direct answer other than people saying that there are issues with the master DB.  As it turned out because i havn’t been using SQL Server (and hence the DB files weren’t being used) Windows has compressed these files to save space (They were coming up with blue colour in the file system).  So I selected all DB and Log files in the C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA folder, went in Properties -> Advanced and unticked the “Compress contents to save disk space” checkbox.  After this all files have turned black and I had no issues starting the service :)

Categories: Programming Tags:

WYSIWYG HTML Editor in .NET WPF, Windows Forms, VB6 in Web Browser

February 4th, 2011 4 comments

I’ve spent a fair bit of time looking for a decent HTML Editor control for a variety of platforms… The platforms on which I needed a decent HTML Editor included Visual Basic 6, .NET Windows Forms and now .NET WPF.  The problem is there is no decent native HTML Editor control for any of these, but what’s worse is there aren’t any good third party controls either, so the only option is really to create your own.

Firstly I needed a HTML Editor for VB6.  The option that most people seem to suggest is to use the DHTMLEdit OCX which has now been retired but can still be deployed and then call various methods on it to do the editing.  You can do something similar with the MSHTML control, but once again it’s quite ugly.  I spent some time searching for a better control and found nBit HTML Editor ActiveX Control but after using it for some time found that it produces SUPER UGLY non standards compliant HTML (i.e. 90s style).  Given that my content is going onto an XHTML page that is not an option.  The control is quite nice in terms of function, but is quite restrictive in what you can do and the ugly HTML is a deal breaker.  I didn’t really want to spend heaps of time on implementing all the buttons in DHTMLEdit or the MSHTML by calling execCommand.  A frequently referred to post for implementing a Windows Forms HTML Editor was also not of much use as it is very basic and doesn’t fit my needs.   Another post on Code Project called WYSIWYG HTML Editor was also not of much use as it didn’t do it how I wanted it.

My initial idea before I began my search was to actually use a WebBrowser control with one of the well established OpenSource HTML Editors like TinyMCE, CKEditor or FCKEditor (now superseded by CKEditor), so I thought I’d see what I can find.  I found an article on CodeProject again where someone has implemented TinyMCE HTML Editor in .NET WindowsForms which was pretty close to what i was looking for.  I did a bit more searching and also found a blog post where a fella has done the same with FCKEditor, titled TinyMCE HTML Editor running in Windows Forms and another one called FCKEditor HTML Editor Running on Desktop.  Between all these posts (and the sample code) I pretty much worked out that this is going to be by far the best way to do this.  Some people on various forms and on StackOverflow had taken issue with using the WebBrowser Control in both Windows Forms and WPF as it’s just a wrapper for the COM WebBrowser and they would prefer a native control, but I say who cares, you just need something that works how you want it from a functional perspective and doesn’t take heaps and heaps of code.

I then did a bit more searching to find out how I can avoid any security issues coming up and found a post about WebBrowser in WPF.  That showed how to avoid a warning by adding some code to the HTML page.

So putting all of this together I managed to easily implement a WYSIWYG HTML Editor on all of the platforms being VB6, Windows Forms and WPF.  What you need to do is actually rather simple, with a few specialty tweaks for each platform:

  1. Download the WYSIWYG HTML Editor of your choice (i.e. TinyMCE, CKEditor, FCKEditor or some other) and put into your project directory
  2. Create a HTML file that will host the control.  This file has the page that will be loaded in the WebBrowser and provides stuff like initialisation for the control as well as simple getter and setter methods.  Make sure to add the stuff at the start of your file to stop the security warning coming up. (i.e. <!– saved from url=(0014)about:internet –>)
  3. Put a WebBrowser control in your window and in the Load (or Loaded) event use the Navigate function of the WebBrowser to open your file.  You can also use the Source or Url Property in WPF and WindowsForms respectively.
  4. When you run the project your WebBrowser should show now.
  5. Next thing is to be able to get and set the contents.
  6. In WPF and WindowsForms you can just use InvokeScript to call the JavaScript methods created in Step 2 to get and set the content of the control.  In VB6 the execScript method doesn’t work quite as well so can’t return a value.  To work around that all you do is add a textarea in a hidden div and use the DOM to access that value and then have your getter and setter javascript methods which you call using execScript get and set the values from the textarea, which you interact with via the DOM using WebBrowser.Document.getElementById(‘htmlArea’).value.

That’s pretty much all you need to implement a fully functional HTML Editor.  You can of course do stuff like implement a user control or a custom control in WPF and WindowsForms to reuse the web browser easily.  You can pass in the configuration and so on from the code and you can even write out the HTML from the code so you don’t need the HTML file.  Whichever way you do it is up to you, but this should certainly give you an idea of how to get the basics working, which is the critical part.

Categories: Programming Tags:

Object Oriented Design Pattern for Database Driven Applications

May 27th, 2010 1 comment

I’ve been working with database driven applications and object oriented programming for a while now and every time I try to marry up the two patterns I cringe.  Many people seem to love ActiveRecord pattern but it has many shortcomings in that it can only deal with very simple applications and everything is in one place.  Likewise DataMapper at the other extreme is quite complex and you end up doing a lot of shuffling of data in the application.  However what’s even worse is that in complex database driven applications you often want to do things like retrieve results which can span multiple tables and you only need to take a little bit of data from each table.  A good example of this is an Order that was placed by a Customer who belongs to an Account.  With a full object oriented domain model you’d have the following options none of which are great…

Read more…

Categories: Programming Tags:

Object Oriented Design for Database Centric Applications

April 27th, 2010 2 comments

I’m writing a few fairly complex apps which are heavily data centric and I seem to be struggling to choose how to best implement such applications.  What I mean by data-centric is that data stored in the database is core to the application and most of the application has to do with working with the database, while the logic tends to be relatively simple.  So what’s the best way to do it…

Read more…

Categories: Programming Tags:

ORM Performance – Have you gone ORM crazy?

April 10th, 2010 5 comments

I gotta say, every framework I look at these days, there seems to be an ORM built-in.  For example in .NET alone (which is a single framework) there’s already LinqToSql and LinqToEntities and then on top of that there’s NHibernate, SubSonic and so on and so forth.  In PHP, every framework I look at seems to have an ORM… They don’t have half the other things that a decent PHP framework actually needs, but they have an ORM.

Is it really all that hard or labourous to write SQL?  Why do you need to learn effectively another language/api for ultimately creating SQL queries when you already know SQL?  Why do you want to destroy the performance of your application?

As crazy as it seams, that’s what seems to be happening.  It’s like people jump on the bandwagon without thinking.  If you read about LinqToSql and LinqToEntities you will find plenty of blog posts saying that performance is terrible and if you want to pre-compile the code needs to be WAY more complex.  Moreover at the moment LinqToEntities generates absolutely shocking SQL for anything but the basic queries.   The same goes for PHP frameworks… ORM takes heaps of code and processing and all for what?  To generate a basic SQL string that you could have written by hand?

Anyways, I guess anyone writing anything moderately serious doesn’t use ORM, but people really need to step back and think about things like performance before they jump on the bandwagon and start churning out SQL over which they have no control using ORM tools.

Categories: Programming Tags: