Wednesday 4 August 2010

How to get database data file path

Recently I needed to create universal script which added new file group and file to database regardless of where the MSSQL server was installed. The reason for creating new file was to split data which were changing a lot (table with cached documents) and data which were more or less static.

There was necessary to find out where is located primary file for current database and then to get just directory where the file was located.
DECLARE @PATH nvarchar(max)

SELECT @PATH = LEFT(filename, LEN(filename) + 1 - CHARINDEX('\', REVERSE(filename)))
FROM  master.dbo.sysaltfiles WHERE db_name(dbid) = db_name() AND name = 'PrimaryFileName'

Monday 10 May 2010

Database Project in Visual Studio 2008

There exists database project in Database Developer edition of Visual Studio 2008. It can be very useful but also painful. The original version needs to have installed local database server for this kind of project but a lot of things can go wrong way. There is a lot of troubleshooting articles on Internet so you think it helps you to resolve the problems quickly - unfortunately not in my case. I have spent almost a day without success until I have found Microsoft® Visual Studio Team System 2008 Database Edition GDR R2. It took me less then one hour to install the package, convert old database project and deploy project. Package installs new database project which doesn't need database server on your local. That was really great and I recommend it GDR to everyone struggling with the original database project.

Wednesday 28 April 2010

How to install Microsoft SQL Server 2008 Management Studio Express

I had on my computer installed SQL Server 2008 Express edition and I was looking for something which will help me to work with it. I have found there is Microsoft SQL Server 2008 Management Studio Express. You can find it on Microsoft download pages.
As a prerequisite you will need to install PowerShell if you already don't have it on your computer. I had trouble to use link to PowerShell 1.0 on the download page so I recommend to use this download link to PowerShell 2.0 on Windows Management Framework page in Windows Management Framework Core section.
When you have installed PowerShell you can start to install Management Studio. I was a bit surprised to see that what I downloaded contains SQL Server installation package. So for the installation of Management Studio 2008 you will need to go Installation > New SQL Server stand-alone installation or add features to an existing installation then pass installation checks and in Feature Selection check Management Tools - Basic.

Friday 16 April 2010

Book recommedation - Co programátory ve škole neučí

At first I would like to apologize to non Czech speaking people. The book I would like to recommend is written in Czech.

I had the book for quite a long time in my bookcase, found it recently and I am glad that I have finally read it. The book discusses difficulties of software development, why a lot of projects are not finished in time or in money. Book doesn't contain any heavy and hard to read theory. On the other hand there are lot of examples from author's work experience. I believe everybody will find out similar examples from his own experience which makes the book very readable.

In short the book contains:
  • specificities of software development
  • frequent reasons why software project fails
  • principals for gathering requirements, writing specification
  • the most frequent mistakes of developers and their reasons
  • how to deal with security holes
  • what can influence speed of software development
  • problems with user interfaces
  • application testing
  • economy side of projects
  • management and communication in development team
  • importance and weaknesses of methodologies, analysis, visual modeling
  • and more...

Sunday 24 January 2010

GDI object leaking example

Finally I have a bit of time to post what caused us GDI objects leaking troubles. I hope it can same time to others who are dealing with the same problem. We ensured that all Graphics, Brushes etc. are destroyed correctly but the application was still leaking. I would like to show part of code which we found when investigating the GDI object leaking issue. We used component which should show first and last and in tooltip some more info. Tooltip was created every time the person was set but the old one was not cleaned up. Each Tooltip use couple of GDI objects which were not released until the application was closed.
public Person SelectedPerson
{
  get { return currentPerson; }
  set
  {
    currentPerson = value;
    Text = GetDescription(currentPerson);
    if (currentPerson != null)
    {
      ToolTip toolTip = new ToolTip();
      toolTip.SetToolTip(this, GetDetailDescription(currentPerson));
    }
  }
}