Tuesday, 19 August 2008

Hyper-V : Error after removing VM




On browsing the Hyper-V Server Manager, I noticed some errors that I had not spotted before >


The Virtual Machines configuration (guid) at 'C:\hyper-V-Path\' is no longer accessible.

For some reason, my attempts at tidying up and moving the vm image files to a new location had not been 100% successful, leaving HyperV to periodically look for the image in the old location (despite the VM working fine from it's new location).

To rectify the situation, this technet post came in rather useful.

Basically >

1 ) Navigate to C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines (if you don't see anything, unhide files and folders via tools > folder options > view > 'show hidden files & folders')

2) Locate the link file that matches the GUID number in your original message.

3) In Hyper-V, click 'Stop Service' (turns off VMMS)

4) Delete the file

5) In Hyper-V, click 'Start Service' to restart the VMMS.

Errors should no longer appear every 2 minutes now.

Note : VMMS is the 'Virtual Machine Management service' and just controls your ability to manage VMs, they continue running even when VMMS has been shut down.

SQL 2008 : Installation on Windows 2008 (VM)

Screen walkthrough of SQL 2008 installation process >


















SQL 2008 : Installer

At first glance, the installer (Enterprise edition pictured) looks a lot more friendly.
More administration functions are available (and are explained) >













Saturday, 16 August 2008

Useful tool : FreeUndelete

FreeUndelete : A file recovery app that is FREE (and works well).

http://www.officerecovery.com/freeundelete/

(It rescued me today when my clumsy fingers deleted a folder on my usb stick)

Wednesday, 13 August 2008

Management Studio Speedup : Shared Memory

If your client and server are the same server (screams silently), for instance in a local development environment then Shared Memory can help.

As of SQL 2005 it is enabled by default, but incase it isn't or you need to check -

1) Set Shared Memory as Enabled for the sql server -


2) Set Shared Memory as Enabled in the client protocols -


Ref : Default SQL Server Network Configuration

Table Design Optimization : Column Sizes Script

I was called on to help with a data problem today.
The developer concerned had misjudged data sizes and hence defined a table that she couldnt import into.
My approach was to define a table with generous text column sizes with a view to reducing them later.

This script shows defined column sizes along with the size of the largest data for that column.
Change the @SCHEMA and @TABLE variables at the top of the script to point it at the table of your choice >
SET NOCOUNT ON 
SET NOCOUNT ON 
SET ANSI_WARNINGS ON
DECLARE @SCHEMA  VARCHAR(50)
DECLARE @TABLE  VARCHAR(50)

SET @SCHEMA = 'DBO'
SET @TABLE  = 'spt_values'

DECLARE  @CURRENTROW INT
DECLARE  @TOTALROWS INT
DECLARE  @COLUMNMAXSIZE INT
DECLARE  @SQLSTRING NVARCHAR(MAX)
DECLARE  @PARAMETER NVARCHAR(500);
DECLARE  @TABLEDETAILS 
  TABLE(UNIQUEROWID     INT   IDENTITY ( 1,1 ),
     TABLE_SCHEMA    VARCHAR(255),
     TABLE_NAME      VARCHAR(255),
     COLUMN_NAME     VARCHAR(255),
     COLUMN_TYPE     VARCHAR(255),
     MAX_LENGTH      INT,
     MAX_DATA_LENGTH INT)
       
INSERT INTO @TABLEDETAILS
          (TABLE_SCHEMA,
           TABLE_NAME,
           COLUMN_NAME,
           COLUMN_TYPE,
           MAX_LENGTH)

SELECT SCHEMA_NAME(O.SCHEMA_ID)  AS TABLE_SCHEMA,
      OBJECT_NAME(O.OBJECT_ID)  AS TABLE_NAME,
      C.NAME                    AS COLUMN_NAME,
      T.NAME                    AS COLUMN_TYPE,
      C.MAX_LENGTH
FROM   SYS.TABLES O
INNER JOIN SYS.COLUMNS C
       ON C.OBJECT_ID = O.OBJECT_ID
INNER JOIN SYS.TYPES T
       ON C.SYSTEM_TYPE_ID = T.SYSTEM_TYPE_ID
      AND T.NAME IN ('CHAR','VARCHAR','NCHAR','NVARCHAR')
WHERE SCHEMA_NAME(O.SCHEMA_ID)  <> 'sys'
AND OBJECT_NAME(O.OBJECT_ID) = @TABLE
AND SCHEMA_NAME(O.SCHEMA_ID) = @SCHEMA
                                
SELECT @TOTALROWS = COUNT(*) FROM   @TABLEDETAILS
SELECT @CURRENTROW = 1
WHILE @CURRENTROW <= @TOTALROWS   
BEGIN     
SET @COLUMNMAXSIZE = 0      
SELECT @SQLSTRING = 'SELECT @COLUMNSIZEMAX = MAX(LEN([' + COLUMN_NAME + '])) FROM [' + TABLE_SCHEMA + '].[' + TABLE_NAME + ']'     FROM   @TABLEDETAILS     WHERE  UNIQUEROWID = @CURRENTROW                               
SET @PARAMETER = N'@COLUMNSIZEMAX INT OUTPUT';          
EXECUTE SP_EXECUTESQL       @SQLSTRING 
     ,       @PARAMETER 
     ,       @COLUMNSIZEMAX = @COLUMNMAXSIZE OUTPUT      
UPDATE @TABLEDETAILS     
SET    MAX_DATA_LENGTH = @COLUMNMAXSIZE     
WHERE  UNIQUEROWID = @CURRENTROW                               

-- DISPLAY PROGRESS (May exceed max results sets if uncommented)     
-- SELECT * FROM @TABLEDETAILS WHERE  UNIQUEROWID = @CURRENTROW       
SET @CURRENTROW = @CURRENTROW + 1   
END      

SELECT   TABLE_SCHEMA
  ,TABLE_NAME
  ,COLUMN_NAME
  ,COLUMN_TYPE
  ,CASE MAX_LENGTH WHEN -1 THEN 'MAX' ELSE CONVERT(CHAR(10),MAX_LENGTH) END AS COLUMN_MAX_LENGTH
  ,MAX_DATA_LENGTH 
FROM @TABLEDETAILS 

Sunday, 10 August 2008

TSQL : List System Stored Procedures

select * from msdb.sys.objects 
where type_desc = 'SQL_STORED_PROCEDURE' and is_ms_shipped = 1