Friday, October 30, 2009

Reconnect SQL user after restore

Have you ever restored a SQL database with a SQL login to a new server and not been able to use the SQL login. So you log into Management Console to create the login, which you can but when you try to give it rights to the database, it says "User, group, or role already exists in the current database."

There is a simple way to fix this. Create user in SQL, connect as sa or admin, select the database you just restored and execute

exec sp_change_users_login 'Auto_Fix', 'yourUserName'

You should see a message like.

The row for user 'yourUserAcct' will be fixed by updating its login link to a login already in existence.
The number of orphaned users fixed by updating users was 1.
The number of orphaned users fixed by adding new logins and then updating users was 0.

Tuesday, October 6, 2009

Correct way to Load a window in WPF

Here is the correct way to load a window in WPF. Notice the hooking the Loaded event in the constructor.

public MainWindow()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Window_Loaded);
//MyBigRoutine(); -- Don't do this.
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
MyBigRoutine();
}

Call to MessageBox.Show in App() prevents StartupURI

Not sure what is going on here but a MessageBox.Show in the ctor of WPF's app.xaml.cs prevents the call to the startupURI object. Removed the call to Show and all is well.

Monday, August 31, 2009

Fixed C000021a BSOD

I am sure there are a myriad of reasons for the deadly C000021a BSOD. In my case I had installed the Exchange management tools in an attempt to update Active Directory Exchange information on my local machine. The install failed and when I rebooted a day or two later it blue screened. When I went to uninstall a KB patch to see if that would fix it, I saw Exchange was running on my machine. I left the patch installed, removed the partial installation and the BSOD was banished.

As always when something crashes ask yourself, "What changed." Answering that question is the shortest route to fixing confusing problems.

Tuesday, August 25, 2009

ItemsControl not showing items

This is simple but easy to forget.

To get data bound to WPF controls you frequently use its DataContext. That works for an ItemsControl but what you probably want is ItemSource instead of DataContext. ItemSource will display a collection whereas DataContext only gives you the first item.

Wednesday, July 1, 2009

True after all

A user told me "I deleted this document image but I should not have been able to do that." Perplexed I checked my code.

private bool OkToDeleteScannedPage()
{
   return true;
}

I replied, "Let me get back to you, I think I know what the problem is." :-)

Wednesday, June 24, 2009

What is the Adorner Layer?

I attended some WPF training in Chicago and talked with one of the presenters, Karl Shifflett. He give the most simple explanation of what the adorner layer is.

It is a layer on top of controls that allows you to decorate them without affecting their layout.

A simple example might be placing a red border around a textbox to highlight an error. If this is done at the adorner layer you will see the red highlight but it will not affect the position of the controls underneath.