Friday, August 11

Shrinking an SQL Server 2000 Transaction Log

I have a database in which the transaction log grew to 19GB, taking up the entire disk space on the server it was on, and which could not be shrunk. Most of the things I found on the net didn't shrink this very much.

However, I found the following script here which worked well, reducing it from 19GB to 52 MB.

http://www.thescripts.com/forum/thread79839.html


use database_name
go
create table shrinkfile(
col1 int,
col2 char(2048)
)

dump tran database_name with no_log
dbcc shrinkfile(logical_name_of_log, 50, TRUNCATEONLY)
go


set nocount on
declare @i int
declare @limit int

select @i = 0
select @limit = 10000

while @i < @limit
begin
insert into shrinkfile values(@i, 'Shrink the log...')
select @i = @i + 1
end

drop table shrinkfile

Thursday, August 10

Updating .NET user controls on the screen

I have some user controls that I need to add a lot of data to. This can be slow as the screen display is updated when each item of data is added. It also makes the dislpay flicker.

I couldn't find an equivalent of the BeginUpdate and EndUpdate functions in .NET 2.0, but it is possible to call the Windows API functions as follows.


private const int WM_SETREDRAW = 11;

[System.Runtime.InteropServices.
DllImport("user32.dll")]
static extern bool SendMessage(IntPtr
hWnd, Int32 msd, Int32 wParam, Int32
lParam);

///
/// Stop updates while we are
/// filling a control with data
///

protected void BeginUpdate()
{
SendMessage(this.Handle, WM_SETREDRAW, 0, 0);
Cursor.Current = Cursors.WaitCursor;
}

///
/// Restart updates
///

protected void EndUpdate()
{
SendMessage(this.Handle, WM_SETREDRAW, 1, 0);
if (Parent != null)
{
Parent.Invalidate(true);
}
Cursor.Current = Cursors.Default;
}


I included these in a base class used by all my user controls, and added code to change the cursor to a wait cursor whilst the control was updating.

Wednesday, August 9

Image List Control

I've had a problem with putting images on a tab control. They appeared fine in the designer, but did not appear when the application was run.

I fixed this by re-ordering the generated InitializeComponent function, and put the code for the ImageList before the code for the tab control.