Tuesday, February 26, 2008

Backup Exec 12: Error "The Backup Exec Server Service detected a schema version mismatch."

[UPDATE] The exact same can happen in BE 12.5. See this post for details. [/UPDATE]

I just tried to update our Backup Exec 11d SP1 to Backup Exec 12 and although all pre-checks were okay and the installation did also not issue any errors, BE didn't started. Checked the event log and the following events were logged:

The Backup Exec Server Service detected a schema version mismatch.

and

The Backup Exec Server Service did not start. An internal error (-536813108) occurred in object 1.

Oh, I really love database schema errors. According to the Symantec support website (http://seer.entsupport.symantec.com/docs/283038.htm or http://seer.entsupport.symantec.com/docs/254014.htm) you need to recreate the entire database if this error happens which means you need to recreate everything from scratch! Thanks for nothing buddy!

Using SQL Server Profiler, I was able to figure out what the problem was. BE uses two tables as schema reference: ControlInfo and Version (you can simply install the SQL Server Mngmt Studio Express and issue an "select * from …" for these two). In this case here, ControlInfo was okay (Version 12.0) but Version still had 11 for some components listed.


There are two SQL files you need to execute against your BEDB database (using Mngmt Studio Express for example):

C:\Program Files\Symantec\Backup Exec\dbupgrade11.5.sql

If there are any errors, you may ignore them.


Once this has run, run

C:\Program Files\Symantec\Backup Exec\dbupgrade11.5-viewandsp.sql

Inside this file, there might be a problem with the following command:

-- sync with bedb.sql version, 1.644

ALTER TABLE [dbo].[Alert] ADD

CONSTRAINT [DF_Alert_UMI] DEFAULT (N'') FOR [UMI]

GO


Simply delete these lines and the script will run to the end. Restarting Backup Exec should now show that BE does no longer throw an schema mismatch error.


Enjoy!

Monday, February 18, 2008

Setting the right font for a Windows Forms application

If you create a new form in Visual Studio, the default font will always be "Microsoft Sans Serif" although you should use a font that depends on the Windows version you are running on. For Windows 2000, XP, Server 2003 you should use "Tahoma" for Vista and above it should be "Segoe UI". In any case, do not use "MS Sans Serif".

Unfortunately, there is no simple property available so the form uses the correct font automatically. Benjamin Hollis has a blog entry about this problem already and his code is quite simple and works quite well.

It just does not take into account if a form contains other, specialized fonts or if the fonts used have special styles (Underlined, Italics etc.) applied. I have tweaked his code a little bit.. ähm.. a lot actually and this is the result: FormFontFixer.

UPDATE: The code is now licensed under a BSD license (see below)


//Original idea and code (3 lines :-) by Benjamin Hollis: http://brh.numbera.com/blog/index.php/2007/04/11/setting-the-correct-default-font-in-net-windows-forms-apps/
//Copyright (C) TeX HeX of Xteq Systems: http://texhex.blogspot.com/ and http://www.texhex.info/
public static class FormFontFixer
{
//This list contains the fonts we want to replace.
static readonly List<string> FontReplaceList
= new List<string>( new string[] { "Microsoft Sans Serif", "Tahoma" } );


static Font _DefaultFont;
static bool _CanFixFonts;


static FormFontFixer()
{
//Basically the font name we want to use should be easy to choose by using the SystemFonts class. However, this class
//is hard-coded (!!) and doesn't seem to work right. On XP, it will mostly return "Microsoft Sans Serif" except
//for the DialogFont property (=Tahoma) but on Vista, this class will return "Tahoma" instead of "SegoiUI" for this property!

//Therefore we will do the following: If we are running on a OS below XP, we will exit because the only font available
//will be MS Sans Serif. On XP, we gonna use "Tahoma", and any other OS we will use the value of the MessageBoxFont
//property because this seems to be set correctly on Vista an above.

if (Environment.OSVersion.Platform==PlatformID.Win32Windows)
{
//95, 98 and other crap
_CanFixFonts = false;
return;
}

if (Environment.OSVersion.Version.Major < 5)
{
//Windows NT
_CanFixFonts = false;
return;
}

if (Environment.OSVersion.Version.Major < 6)
{
//Windows 2000 (5.0), Windows XP (5.1), Windows Server 2003 and XP Pro x64 Edtion v2003 (5.2)
_CanFixFonts = true;
_DefaultFont = SystemFonts.DialogFont; //Tahoma hopefully
}
else
{
//Vista and above
_CanFixFonts = true;
_DefaultFont = SystemFonts.MessageBoxFont; //should be SegoiUI
}
}

public static void Fix(Form form)
{
//If we can't fix the font, exit
if (_CanFixFonts == false)
{
return;
}


//Now start with the real work...
foreach (Control c in form.Controls)
{
//only replace fonts that use one the "system fonts" we have declared
if (FontReplaceList.IndexOf(c.Font.Name) > -1)
{
//Now check the size, when the size is 9 or below it's the default font size and we do not keep the size since
//SegoiUI has a complete different spacing (and thus size) than MS SansS or Tahoma.

//Also check if there are any styles applied on the font (e.g. Italic) which we need to apply to the new
//font as well.

bool bUseDefaultSize = true;
bool bUseDefaultStyle = true;

//is this a special size?
if ((c.Font.Size <= 8) || (c.Font.Size >= 9))
{
bUseDefaultSize = false;
}

//are any special styles (bold, italic etc.) applied to this font?
if ( (c.Font.Italic == true) ||
(c.Font.Strikeout == true) ||
(c.Font.Underline == true) ||
(c.Font.Bold == true))
{
bUseDefaultStyle = false;
}

//if everything is set to defaults, we can use our prepared font right away
if ((bUseDefaultSize == true) && (bUseDefaultStyle == true))
{
c.Font = _DefaultFont;
}
else
{
//There are non default properties set so
//there is some work we need to do...


//Restrive custom font style
FontStyle Style = FontStyle.Regular;
if (bUseDefaultStyle == false)
{
if (c.Font.Italic) {
Style = Style | FontStyle.Italic;
}
if (c.Font.Strikeout) {
Style = Style | FontStyle.Strikeout;
}
if (c.Font.Underline) {
Style = Style | FontStyle.Underline;
}
if (c.Font.Bold){
Style = Style | FontStyle.Bold;
}
}

//Retrive custom size
float fFontSize = _DefaultFont.SizeInPoints;
if (bUseDefaultSize == false)
{
fFontSize = c.Font.SizeInPoints;

}

//Finally apply this font...
Font font = new Font(_DefaultFont.Name, fFontSize, Style, GraphicsUnit.Point);
c.Font = font;

}
}
}

}
}


Copyright (c) 2008, TeX HeX (http://www.texhex.info/)

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of the Xteq Systems (http://www.xteq.com/) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Saturday, February 16, 2008

Security Neutral Mutex

We have just completed a project where we had a very “strange” requirement: A Mutex that is normally created by a service but might also be changed or created by the application running as a limited user. Before .NET, we would simply have created a Mutex with a NULL DACL but this is no longer possible because the Mutex Class will actively prevent this.

Fortunately, we found a blog post where the author simply created a Mutex and give EVERYONE full rights on the Mutex which is basically the same as a NULL DACL: http://rdn-consulting.com/blog/2007/09/14/more-on-using-a-named-mutex-in-vista/

We changed the code a little bit and here is the result:


//Original Code: http://rdn-consulting.com/blog/2007/08/20/kernel-object-namespace-and-vista/

public static Mutex Create(string Name)
{
bool bTrash;
return Create(Name, out bTrash);
}

public static Mutex Create(string Name, out bool MutexWasCreated)
{
//Always use global scope
string name = @"Global\" + Name;

MutexSecurity sec = new MutexSecurity();

MutexAccessRule secRule = new MutexAccessRule(

new SecurityIdentifier(WellKnownSidType.WorldSid, null),

MutexRights.FullControl, AccessControlType.Allow);

sec.AddAccessRule(secRule);

bool mutexWasCreated;

Mutex m = new Mutex(false, name, out mutexWasCreated, sec);

MutexWasCreated = mutexWasCreated;

return m;

}

Friday, February 8, 2008

XQGetOSVer 3.0 available

We have just released Xteq Systems GetOSVersion 3.0 (XQGetOSVer).

XQGetOSVer returns a number for each detected OS (Windows 95 up to Windows Server 2008) and can therefore easily be used for batch files where you want to execute special commands depending on the OS in use.