Moving a table to another filegroup

by Syska 9. June 2010 16:10

So, how does one move a table to another filegroup.

Say I have the following table:

CREATE TABLE [dbo].[Tests](
    [TestID] [int] NOT NULL,
    [TestInt] [int] NOT NULL,
    [TestBigInt] [bigint] NOT NULL,
 CONSTRAINT [PK_Tests] PRIMARY KEY CLUSTERED 
(
    [TestID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

Since tables are always stored with the clustered index. Moving the clustered index, also moves the table. So if we want to move the table, we can recreate the CLUSTERED index on another storage group. Here we are moving from “PRIMARY” to “PRIMARY2”.

CREATE UNIQUE CLUSTERED INDEX PK_Tests
   ON dbo.Tests(TestID)
   WITH DROP_EXISTING
ON [PRIMARY2]

This can also be done when the table is online and is also moving the indexes. There are some performance diff if you are moving the table while its still online, so consider if its worth the extra overhead.

You can extend the relation index options with the create index command like this, to move it while its still online.

CREATE UNIQUE CLUSTERED INDEX PK_Tests
   ON dbo.Tests(TestID)
   WITH (DROP_EXISTING = ON, ONLINE = ON)
ON [PRIMARY2]

Tags: ,

MSSQL

Find duplicate rows in MS SQL

by Syska 17. March 2010 17:51

So, the other day I was reading T-SQL: Why “It Depends” and in the comments section a guys suggested using the “PARTITION BY” in the OVER clause.

I thought was the heck does that do … so i searched the web for an answer … and wow … what a great way to find duplicate post … and possible also a lot of other things it can be used for that I haven’t thought about.

To the code …

WITH Data AS
(
	SELECT 
	ROW_NUMBER() OVER ( PARTITION BY CID ORDER BY Added DESC) AS DupeNumber
	,CID, Added
FROM Servers
)
SELECT * FROM Data Where DupeNumber >= 2

This will check for dupes on the CID column … and then select all the rows where DupeNumber is over or equal to 2. You could then instead of select it … you could delete it.

Fancy way … I like it.

Tags: , , ,

windows 7

Windows 7 Tips – Shortcuts

by Syska 5. December 2009 18:12

In windows 7 there are several great shortcuts that can make you day in front of the computer better, and here are some of them than I use often … and some of them I just know of.

Windows + Arrow

You can move the active window around on the screen.

capper-16 capper-18
Windows + Left Arrow
Will dock the window to the left
Windows + Right Arrow
Will dock the window to the right
capper-19 capper-17
Windows + Arrow up
Will maximize the window to the current screen.
Windows + Arrow Down
(do it again and it will minimize)

Windows + Shift + Arrow up

Like the shortcuts above, hitting these keys will stretch the active window vertically. Pressing Windows + Down will restore it to the previously size.

Alt + P

Alt_P

When you are in a explorer and want to preview things. Pressing Alt + P will bring up a preview window in the left part of the Explorer window. It can be used on all types of documents … but there is a startup time for them and depending on the time of document the first preview can take some time show.

Windows + + ( plus key ) and Windows + – ( minus key )

capper-21

Brings up the magnifier, so if you are showing something on a projector on a daily basis this is great. Consider you are showing how a program works, instead of lowering the resolution to something like 800x600 … you can just quickly zoom in on it.

You can of cause zoom out again using the other shortcut – Windows + – ( minus key )

capper-20 

Windows + P

capper-8

Will manage multiple monitor setup more easily or if you just connected a projector. Pressing the key P again while holding down the Windows key will loop over the available options.

Windows + [number]

capper-23

Here in my Taskbar i have:

  1. visionapp Remote Desktop 2010
  2. Visual Studio 2008
  3. Firefox ( of cause )
  4. Messenger
  5. Total Commander
  6. Windows Explorer
  7. Photo Viewer

Pressing Windows + 7 and this will bring up the Photo Viewer if there were only one instance. Here i got 2 so it lets to toggle between them. If there are no instance running of the program it will start one for you.

Ctrl + Click

capper-15

Holding down Ctrl while clicking a program icon in the taskbar will toggle between the instances. For example like in the above, that would toggle between the 2 instances of the Photo viewer. Here used with two instances of the Windows Explorer started.

Ctrl + Shift + Click

This will start the program clicked on with full administrative rights on the system. While not very useful I, it can be used as pinned programs to the Taskbar, would require more clicks, so it saves a little time :-)

Conclusion

These are some of the best shortcuts I have found to date, but there are still more I guess … so in the future I will update this blog post if I find any.

You you got any that you think is missing, please to post them as comments or contact me, and I will add them.

Tags: , , ,

Tech-Ed Europe 2009 round up

by Syska 22. November 2009 19:46

As a MSP, we were invited to join Tech-Ed Europe 2009 conference, in which we were 3 Danish MSP’s that accepted that offer, that was Jacob Korsgaard, Allan Juhl Petersen and Mikael Syska (myself).

As I missed the first flight, cause I read the departure time wrong (god damn). I first arrived Monday morning 8:30 in Berlin, and then had to go to the Hotel with my luggege and just to get a shower, cause I smelled like crap after spending the night in the Airport.

I then took the S-Barn to the South entrance to Messe Berlin, and I then thought I was maybe one of the last people to arrive, but I was wrong.

As you can see on the picture above, there were lost of people arriving the same time as me, so after all, I was not that late at the first day, even though I missed the flight I was supposed to have taken.

 

When I entered the registration room, holy fuck there were many people waiting to get there badge. But it went fairly quickly. But then … 3 people in front of me, there were some problems with a persons registration and it took like 30 minutes (excluding to the 10 minutes i had allready spend in the queue, where 100 people had completed there registration) before they send him over to  another booth, where I guess they can see some additional information about the attendees. There must have been something completely wrong, I don't know. But at last I got in … weeeee.

The keynote the first day was about “The new Efficiency”. In short terms, its about cost savings, productivity and innovation. They talked about where companies have used Microsoft products to achieve these 3 goals.

Don’t got a phone with wireless access, no problem. There were plenty of computers freely available to use, and also access to a printer. So you could plan your schedule or maybe just print it, if you forgot to do it at home.

So … does we only listen to speakers, talk with other developers … not at all, 2 days at the conference there were beers, wine and food. That’s nice, and while you were having a drink you could also walk around and talk to the different speakers, exhibitors and of cause  all the other attendees.

Two of the Danish MSP won the AntMe battle, Jacob(with the WOW game in his hands) and then Allan, the 2 persons to the left on the picture. Though out the week, at the Community lounge, you were given the opportunity to program the Ants what they should do, collect food, kill bugs or attack the other ant colonies. There goals were clear … kill kill kill after they watched a demo and there strategy gave them the victory. The biggest problem was to get the game back to Denmark, because it was so big. But our ADE, Martin Esmann knew a danish guy that had traveled by car to Tech-Ed Europe, so he could bring it with him is the car to Denmark.

Yes, there are also Band Hero is here … I guess its all over the world now.

So what else did I see at the conference.

In the future I will blog about the following

Windows 7

Mostly tip and tricks ... and what i find usefull in Seven.

Hyper-V R2

How my the reinstallation of my Windows Server 2008 to Windows Server 2008 R2 went. The people at the virtualization booth said that the preferred way was to reinstall the system completely to avoid any problems. Then just export the guess systems that are running, and afterwards import them again.

Visual Studio 2010 Team Foundation Server

I have never used VSTS, but as I attended a few of the sessions about it, I could understand that the 2010 version is way better. MS people has to say this of cause, but other attendees were also very positive of 2010 and the new features are great.

  • Graphical administration, instead of small console apps.
  • Integrated Rollback are also supported now. Undo of rollback are not supported but as they said, you can rollback to a previously version to get the same effect. So rollback a rollback … that's like a undo :-)
  • Better integration into Visual Studio, braches, setup etc.
  • Installation in less than 20 minutes.
  • And even more I will look into later.

MSSQL 2008 Spatial Data

I attended a session about spatial data in SQL and what you have to watch out for and how to debug performance problems. If I get the time I will try to make a little sample app in WPF with a SQL server with spatial data. But not sure I get the time. If one ever want to use map data, this is the way to go. So easy to do mapping etc.

WPF - Windows Presentation Foundation

As I have started learning WPF, I will blog about some of the nice and bad things I find.

What i missed were at TechEd Europe 2009

  • Something about Silver light 4
  • Internet at the hotel
  • Shorter distance between all the halls and soda and coffee close to the sessions.
  • That we did not get the bottle to have water in, so we had to get our own, totally odd.

My over all score is 4/5

The next time i attend such a big conference, I will have more knowledge how to spend my time and not waste it on session I think could be interesting. Then just skip it and and use the time with the exhibitors booths.

yoda

Tags: , , ,

Creating a bootable Windows 7 USB media

by Syska 16. November 2009 00:16

So … my mother was uning a old windows 2000 and had been doing it since it was installed, only a few thing updated in the time and now problems what so ever with it. I keep using “If it aint broken dont update it”.

But the bank she's been using so supporting Windows 2000, the other day, so I kind a have to update the operating system now … :-(

But the computer she got don’t have a DVD drive so what to do …

Boot from a USB media, what the first option I came across, but while not sure the hardware support it, I opened my favorite seach page … google of cause and found Kevin’s blog. For reference there is a copy of Kevin steps below.

Witch looked really simple … so I started with that.

So … now I’m installing from a USB Media … awesome.

Problems I ran into:

Graphics card: Asus 7100 Pro aka GeForce2 MX 400, Windows 7 did not have a driver and I could not find one on nvidia.com so I went to google again and found this: Windows 7 and Geforce2 GTS. The file has been attached to the post. Seems to run great, and now I can run more than: 1024x768, YAHHH. Forceware 71.89 working under Win7.ZIP (18.76 mb)

 

Kevin’s steps: taken from Kevin’s blog post

Required:

  • USB Flash Drive (4GB+)
  • Microsoft OS Disk (Vista / Windows 7)
  • A computer running Vista / Windows 7

Step 1: Format the Drive
The steps here are to use the command line to format the disk properly using the diskpart utility. [Be warned: this will erase everything on your drive. Be careful.]

  1. Plug in your USB Flash Drive
  2. Open a command prompt as administrator (Right click on Start > All Programs > Accessories > Command Prompt and select “Run as administrator”
  3. Find the drive number of your USB Drive by typing the following into the Command Prompt window:
    diskpart
    list disk
    The number of your USB drive will listed. You’ll need this for the next step.  I’ll assume that the USB flash drive is disk 1.
  4. Format the drive by typing the next instructions into the same window. Replace the number “1” with the number of your disk below.
    select disk 1
    clean
    create partition primary
    select partition 1
    active
    format fs=NTFS
    assign
    exit
    When that is done you’ll have a formatted USB flash drive ready to be made bootable.

Step 2: Make the Drive Bootable 
Next we’ll use the bootsect utility that comes on the Vista or Windows 7 disk to make the flash drive bootable.  In the same command window that you were using in Step 1:

  1. Insert your Windows Vista / 7 DVD into your drive.
  2. Change directory to the DVD’s boot directory where bootsect lives:
    d:
    cd d:\boot
  3. Use bootsect to set the USB as a bootable NTFS drive prepared for a Vista/7 image. I’m assuming that your USB flash drive has been labeled disk G:\ by the computer:
    bootsect /nt60 g:
  4. You can now close the command prompt window, we’re done here.

Step 3: Copy the installation DVD to the USB drive
The easiest way is to use Windows explorer to copy all of the files on your DVD on to the formatted flash drive.  After you’ve copied all of the files the disk you are ready to go.

Step 4: Set your BIOS to boot from USB
This is where you’re on your own since every computer is different. Most BIOS’s allow you to hit a key at boot and select a boot option.

Forceware 71.89 working under Win7.ZIP (18.76 mb)

Tags: ,

Windows

Microsoft Visual Studio 2010 BETA2 Available for download

by Syska 20. October 2009 08:50

So the other day I was talking to my fellow MSP’s(Microsoft Student Partner) if some of of was using VS 2010. Most of us had tried the beta but not really used it cause it still had a slow UI, which should be fixed in the next release, BETA2.

So while writing this, I also began the installation of: Visual Studio 2010 Ultimate Beta 2 Web Installer (x86) - (English). Instead of downloading the normal ISO image, I would try the Web Installer this time. More on that later how it went.

I will later write something about the new features as I start using Vs 2010. For now just take a look at this link: Visual Studio 2010 and .NET Framework 4 Beta 2 Walkthroughs

Tags: , , ,

Virtual Earth 6.1 SDK - Context Menu

by Syska 20. August 2008 01:02

Google is the first one to do many things on the internet, and the others just follow ... and so did Microsoft here:

Made it possible to search the world in a virtual map ... but with different views of the earth and how it looks today. I won't be going into detailt about, seach for live maps or google maps if you want to know more detailts about it.

Google's: http://maps.google.com/
Microsoft: http://maps.live.com/

I havent used any of them very much, but was asked if I create a little site taking advantage of Live maps from Microsoft.

Links of interrest:
Microsoft Virtual Earth - here you can find all you need to get started, but I will still point out some of the resources I have used.

Virtual Earth JavaScript Intellisense Helper - very nice, helped me alot during my exploration though of it.

Creating a Context Menu to support additional options to Virtual Earth/Live maps

1st step

The example is taken from: Virtual Earth Interactive SDK

Create a html document with the following.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head> <title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1"></script>
<script type="text/javascript">
var map = null;
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
}
</script>
</head>
<body onload="GetMap();">
<div id='myMap' style="position:relative; width:400px; height:400px;"></div>
</body>
</html>

2nd step

Add the following to the GetMap() fucntion:

map.AttachEvent("onclick", ShowPopupMenu);

3rd step

Add the following html to the file ( just above the myMap div would be fine ):

    <div id="menu">
        <ul id="popupmenu" class="pmenu">
            <li><a href="#" onclick='RemovePopupMenu(); alert("First");'>First</a></li>
            <li><a href="#" onclick='RemovePopupMenu(); alert("Second");'>Second</a></li>
            <li><a href="#" onclick='RemovePopupMenu();'>Exit</a></li>
        </ul>
    </div>

4th step

Add the following function to the java-script block:

function ShowPopupMenu(e) {
    if (!e.rightMouseButton) {
        RemovePopupMenu();
        return;
    }

    var menu = document.getElementById('popupmenu');

    menu.style.display = 'block'; //Showing the menu
    menu.style.left = e.clientX + "px"; //Positioning the menu
    menu.style.top = e.clientY + "px";
}

function RemovePopupMenu() {
    document.getElementById("popupmenu").style.display = 'none';
}

5th step

Add some css style after the <meta> tag in the top of the html document:

<style type="text/css" media="screen">
    ul, li {margin:0;padding:0;}

    ul.pmenu
    {
        display: none;
        position:absolute;
        margin: 0;
        padding: 1px;
        list-style: none;
        width: 150px; /* Width of Menu Items */
        border: 1px solid #ccc;
        background: #235087;
        z-index:10;
    }

    ul.pmenu li { position: relative; }

    ul.pmenu li a
    {
        display: block;
        text-decoration: none;
        color: White;
        padding: 2px 5px 2px 20px;
    }

    ul.pmenu li a:hover
    {
        background:#335EA8;
        color:white;
    }
</style>

Live Demo

You can watch a live demo of it here: http://ifyoudo.net/demo/ve/

Done

Thats all ... there are alot of other examples out on the internet, when I was searching for it, but they all used some earlier versions of the Virtual Earth SDK, and did not work with the current version when I was writing this.

I hope you will find this usefull, please contact me if there are any questions.

Tags: , , , , ,

Project

MailScannerWatermark Plugin For Microsoft Exchange 2007

by Syska 7. August 2008 19:42

If you have more offsite Exchange 2007 installations and dont want to route all mail traffic to the MailScanner box itself to save bandwidth, this is the perfect solution.

Please contact me if there are any missing options in the implementation.

Index

  • How to install the MailScannerWatermark plugin for Microsoft Exchange 2007
  • How to uninstall a TransportAgent for Microsoft Exchange 2007
  • Conclusion
  • Files

How to install the MailScannerWatermark plugin for Microsoft Exchange 2007

File are placed in the bottom.

1st step

Extract the content of the zip archive. The content should look something like below.

Filestructure

  • MailScannerWatermark 
    • AgentProject ( source code )
    • MS Files
      • Microsoft.Exchange.Data.Common.dll
      • Microsoft.Exchange.Data.Transport.dll
    • Files
      • Create.Event.Source.ps1
      • MailScannerWatermark.dll
      • Settings.reg
Copy "MailScannerWatermark.dll" from the "Files" directory to a folder on the Microsoft Exchange 2007 server. I have used "C:\IfYouDo.Net\" and placed the file there. You may use whatever directory you want.

2nd step

Install the plugin with the following command in the Power Shell:

[PS] C:\>install-transportagent

cmdlet install-transportagent at command pipeline position 1
Supply values for the following parameters:
Name: MailScannerWatermark
TransportAgentFactory: IfYouDo.Net.MailScannerWatermarkFactory
AssemblyPath: C:\IfYouDo.Net\MailScannerWatermark.dll

Identity                                           Enabled         Priority
--------                                           -------         --------
MailScannerWatermark                               False           10
WARNING: Please exit Powershell to complete the installation.
WARNING: The following service restart is required for the change(s) to take
effect : MSExchangeTransport


Notes:

  • The AssemblyPath must to changed acordingly to the FolderPath used in step 1.
  • Make sure the permissions are right on the assembly file else it will complain about the Path are incorrect.

3rd step

Enable the plugin in Power Shell with:

[PS] C:\>Enable-TransportAgent MailScannerWatermark

4th step

In the folder used above, there should be a file named "settings.reg", double click it to register the values to the register database and then edit the values or do it manualy before with notepad or similar program:

Change the values to suit your needs:

 Debug  True/False
 HeaderName  HeaderName used in the MailScanner installation, excluding the ":" (colon). The HeaderName will be trimmed for any ":" in the end, just to make sure no one just copies the HeaderName from the MailScanner settings.
 Secret  The secret used in the Mailscanner installation, if MultipleDomains are "False"
 Expiry  How many days the Watermark is valid.
 MultipleDomains  True/False. If "True", it will look for the domain in the regdb, and use that secretkey if found. If the domain is not found, and "Secret" is in the regdb it will use that secretkey else it will just skip that domain. If "False" it will use "Secret" value as key for all doamins.
 domainname.tld  secretkey

Example 1 - Same secret for all domains.

Example 2 - domain1.com and domain2.com have diff keys but "Secret" are used for all others

Remove the "Secret" key from the regdb, if you dont want other domains than domain1.com and domain2.com to get tagged with a Watermark.

5th step

Run the following command in the Power Shell to restart the Microsoft Exchange Transport.

[PS] C:\>Restart-service MSExchangeTransport

6th step

Run the "Create.Event.Source.ps1" from the Files folder, this will create an EvenLog Source "MailScannerWatermark" in the Application log.

7th step

First ... use debug ... there will be  some info about the time found, msgid, etc. so we know its right.

Then send an email to a valid recipient, to see that the watermark is actually there.
Then send an email to an invalid recipient, that you know will send a message back to you, and make sure its get a NDR.
Then telnet to a public ISP SMTP server, and make a fake email, that we know will not get a valid watermark.

All text below with a "C:" before the line are client commands, and needs to be written by you, the others are server responses.

Make a "telnet" connected to a smtp. Like the below if you are running Windows. The prompt may differ a little.
cmd> telnet some.smtp.tld 25
S: 220 smtp.example.com ESMTP Postfix
C: HELO relay.example.org
S: 250 Hello relay.example.org, I am glad to meet you
C: MAIL FROM:<bob@example.org>

S: 250 Ok
C: RCPT TO:<alice@example.com>
S: 250 Ok
C: RCPT TO:<theboss@example.com>
S: 250 Ok
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: Subject: Test message
C: Hello Alice.
C: This is a test message
C: Your friend,
C: Mikael Syska
C: .
S: 250 Ok: queued as 12345
C: QUIT
S: 221 Bye


The above example should be with a valid from address and an invalid recipient address, so we will get a NDR, but this time it should be taken by the MailScanner server, since it does not contain a valid Watermark.

How to uninstall a TransportAgent for Microsoft Exchange 2007

1st Step

Will give you a list of all installed transportagents

[PS] C:\>transportagent
Identity                                           Enabled         Priority
--------                                           -------         --------
Transport Rule Agent                               True            1
Journaling Agent                                   True            2
Connection Filtering Agent                         True            4
Content Filter Agent                               True            5
Sender Id Agent                                    True            6
Sender Filter Agent                                True            7
Recipient Filter Agent                             True            8
Protocol Analysis Agent                            True            9
MailScannerWatermark                               True            10


2nd Step

From the list above, I have choosen to uninstall the "MailScannerWatermark" plugin.

[PS] C:\>uninstall-transportagent MailScannerWatermark

Confirm
Are you sure you want to perform this action?
Uninstalling Transport agent "MailScannerWatermark". A service restart is
required for the change to take effect.
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "Y"):


Type "Y" to confirm that you want to uninstall it

3rd Step

Run the following command in the Power Shell to restart the Microsoft Exchange Transport.

[PS] C:\>Restart-service MSExchangeTransport

Now the plugin is uninstalled from the system.

Conclusion

This have been very fun to play with Microsoft new Transport-Agents in Exchange 2007. There are very powerfull and there are endless ideas of what you can do now ... in a very easy way compared to Event Sinks in Exchange 2003.

Any comments are most welcome ...

Note: This could be made to work with EventSinks also in Exchange 2003, but I dont have the knowledge nor time to do it ... if someone makes it, I will happily post it here.

Files

Old version will be taken offline and will not be available.

Version Download Changes
v.2 MailScannerWatermark.zip (617.01 kb) Updated to support multiple "Secrets"
v.1 MailScannerWatermark.zip (612.53 kb) First version

Tags: , , , , ,

Project

About the brain

Mikael SyskaMikael Syska

Student at the Engineering College of Aarhus.

Microsoft Student Partner ( MSP )

On this blog I will primarily write about .NET, MSSQL & projects I'm working on ... and of course there will some off topic posts :-)