DECLARE DbCursor CURSOR
READ_ONLY
FOR select Name from sys.databases where Name <> 'tempdb'
DECLARE @DbName varchar(40)
OPEN DbCursor
FETCH NEXT FROM DbCursor INTO @DbName
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
declare @date varchar(100)
set @date = convert(varchar(4), datepart(yyyy, getdate()))
set @date = @date + '-'
set @date = @date + convert(varchar(4), datepart(mm, getdate()))
set @date = @date + '-'
set @date = @date + convert(varchar(4), datepart(dd, getdate()))
set @date = @date + '-'
set @date = @date + convert(varchar(4), datepart(hh, getdate()))
set @date = @date + '-'
set @date = @date + convert(varchar(4), datepart(n, getdate()))
set @date = @date + '-'
set @date = @date + convert(varchar(4), datepart(s, getdate()))
set @date = @date + '-'
set @date = @date + convert(varchar(4), datepart(ms, getdate()))
set @date = @date + '-'
declare @BackUpDeviceName varchar(150)
set @BackUpDeviceName = @DbName + '_BackupDevice'
declare @BackUpDeviceFile varchar(150)
set @BackUpDeviceFile = 'c:\SqlBak\' + @DbName + '_' + @date + '.BAK'
if (exists (select * from master.dbo.sysdevices
where name = @BackUpDeviceName))
exec sp_dropdevice @BackUpDeviceName
exec sp_addumpdevice 'disk', @BackUpDeviceName, @BackUpDeviceFile
backup database @DbName TO @BackUpDeviceName
exec sp_dropdevice @BackUpDeviceName
print @DbName + ' is backed up as of ' + @date
FETCH NEXT FROM DbCursor INTO @DbName
END
END
CLOSE DbCursor
DEALLOCATE DbCursor
GO
Thursday, December 22, 2005
Backing up SQL 2005
Because the beta version of SQL 2005 we are using did not come with the management studio, we had to back up the server manually (with tSQL) and I wrote the following script which backs up every single database on the server (except tempdb). Here it is:
Thursday, December 15, 2005
Implementing the WinForm Singleton Pattern
In a recent project I had to implement the Singleton WinForm Pattern. This Pattern is essential for performance and pretty darn easy to use.
The idea is that each form in the WinForm application has only one unique instance in an individual AppDomain. So, here's what you don't do:
Application.MyForm _MyForm;
_MyForm = new Application.MyForm();
Why? Because calling New results in a brand new instantiation of the form. Instead, with Singleton we ask for the instance of the form like this:
Application.MyForm _MyForm;
_MyForm.GetInstance();
How does it work? Well, the only form that exists is a private static variable that instantiates when the static constructor fires. Here's what it looks like:
public sealed class MyForm
{
private static MyForm m_instance = new MyForm();
public static MyForm GetInstance()
{
return m_instance;
}
}
Is it thread safe? Yes.
It's good practice to make the class sealed.
Hey! This isn't limited to WinForms - any class can use it.
I hope this helps.
Easy huh?
Monday, December 12, 2005
Mark Job died...
It’s impossible for me to believe that Mark just suddenly died of a brain aneurism. Mark headed Immedient’s Business Intelligence practice in Denver and, frankly, he was my friend.
I have never had someone on my Instant Messenger list die – and I am not sure if I can bring myself to delete his profile. Then again I don’t know if I can leave it either.
Mark knew this stuff as well as anyone; we sat next to each other in Seattle at the Business Scorecard air lift; I spoke for him once at Analytics Avenue about Reporting Services. And now he’s dead.
Uhg. My stomach hurts.
I have never had someone on my Instant Messenger list die – and I am not sure if I can bring myself to delete his profile. Then again I don’t know if I can leave it either.
Mark knew this stuff as well as anyone; we sat next to each other in Seattle at the Business Scorecard air lift; I spoke for him once at Analytics Avenue about Reporting Services. And now he’s dead.
Uhg. My stomach hurts.
Subscribe to:
Posts (Atom)