Thursday, September 22, 2011

How to stop and start RS server

Step 1:

DECLARE @Time VARCHAR(20), @cmdline VARCHAR(200)

SET @Time  = CONVERT(VARCHAR(2),DATEPART(Hour, DATEADD(Mi, 1,GETDATE())))  +':' + CONVERT(VARCHAR(2), DATEPART(Mi, DATEADD(Mi, 1,GETDATE())))
SET @cmdline = 'AT \\svanwarsql02 '+@Time+' NET STOP ReportServer'
EXEC master..xp_cmdshell @cmdline

SET @Time  = CONVERT(VARCHAR(2),DATEPART(Hour, DATEADD(Mi, 1,GETDATE())))  +':' + CONVERT(VARCHAR(2), DATEPART(Mi, DATEADD(Mi, 2,GETDATE())))
SET @cmdline = 'AT \\svanwarsql02 '+@Time+' NET START ReportServer'
EXEC master..xp_cmdshell @cmdline

Step 2:

Wait for 5 mins to allow step 1 to finish

WAITFOR delay '00:05:00'

How to search one specific object among databases


-- Run on the SVANWARSQL02

DECLARE @SearchString VARCHAR(255)

DECLARE @tblName    VARCHAR(300)      -- each table from  select * from StagingData.dbo.stgETL0Cleanup  delete from StagingData.dbo.stgETL0Cleanup where searchstr ='ch_ivr_audit'
                           
DECLARE @db_name1    VARCHAR(300)
DECLARE @db_name2    VARCHAR(300)
DECLARE @sql        VARCHAR(500)
DECLARE @sql1       VARCHAR(500)
DECLARE @counter    INT
DECLARE @error_num  INT

DECLARE @name VARCHAR(50)

SET @counter = 0
--set @name = 'blabla'
--select searchstr,@name from StagingData.dbo.stgETL0Cleanup

--TRUNCATE TABLE StagingData.dbo.ETL0_SearchObjectResults

--IF NOT EXISTS(SELECT * FROM StagingData..sysobjects WHERE ID = OBJECT_ID('StagingData.dbo.ETL0_SearchObjectResults'))
--   BEGIN
--    CREATE TABLE StagingData.dbo.ETL0_SearchObjectResults
--        (   
--        sp_name                        VARCHAR(300),
--        dbName                        VARCHAR(300),
--        tblName                        VARCHAR(300),
--        ID                            VARCHAR(1000)
--        )
--    END
   
--TRUNCATE TABLE StagingData.dbo.ETL0_lkpResults   
   
--IF NOT EXISTS(SELECT * FROM StagingData..sysobjects WHERE ID = OBJECT_ID('StagingData.dbo.ETL0_lkpResults'))
--   BEGIN
--    CREATE TABLE StagingData.dbo.ETL0_lkpResults
--        (   
--        dbName                        VARCHAR(300),
--        tblName                        VARCHAR(300),
--        ID                            VARCHAR(1000)
--        )     
--   END 
                   
--DECLARE tbl_cursor CURSOR FOR
--SELECT searchstr
--FROM StagingData.dbo.stgETL0Cleanup                   

                                                       
DECLARE db_cursor CURSOR FOR 
SELECT name                 -- get the list of all databases on this server
FROM MASTER.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb','ReportServer','ReportServerExternal','ReportServerExternalTempDB','ReportServerTempDB',
'Strata','TelcoReconciliation','TestForReplication','VanBMCProduction_Backup','MapInfo','RepMD','CommonEvent','CommonEvent_2011Q1',
'CommonEvent_2011Q2','CommonEvent_2011Q3','QuestSoftware','QuestWorkDatabase','ProdAdminDB_Backup','EventData_Detail_cw','Chr_Utils_WrkDB',
'VanReplicaOld'
) 
ORDER by name
   
   
    OPEN db_cursor

 
FETCH NEXT FROM db_cursor INTO @name

While @@FETCH_STATUS = 0
BEGIN
    --OPEN tbl_cursor
    --FETCH NEXT FROM tbl_cursor INTO @tblname
   
    --    While @@FETCH_STATUS = 0
    --        BEGIN   
           
                --SET @counter = @counter + 1
                       
                SET @db_name1 =@name+'.dbo.'+'syscomments'
                SET @db_name2 =@name+'.dbo.'+'sysobjects'      
               

                SELECT @sql =                                        
                'SELECT DISTINCT '''+@name+''',o.name,'+CONVERT(varchar(1000),@counter)+' From '+@db_name1+' s JOIN'+' '+@db_name2+' o ON s.id = o.id '
               
                --SELECT @sql = @sql+' WHERE  s.text like '+'''%'+@tblname+'%'''
                SELECT @sql = @sql+' WHERE  s.text like '+'''%'+'cc_optimal_settlement_toberemoved'+'%'''   --->>>>> individual search, change the name between % %
                --SELECT @sql ='INSERT INTO StagingData.dbo.ETL0_SearchObjectResults (sp_name,ID)  '+@sql   
                EXEC(@sql)
               
                Select @error_num = @@ERROR               
                IF @error_num <> 0  Print @sql
               
                --SELECT @sql1 = 'SELECT '''+@name+''','''+@tblName+''','+CONVERT(varchar(1000),@counter)
                --SELECT @sql1 = 'INSERT INTO StagingData.dbo.ETL0_lkpResults(dbName,tblName,ID) '+@sql1
       
                --EXEC(@sql1)
               
                --Select @error_num = @@ERROR
                --IF @error_num <> 0  Print @sql
               
               
                --FETCH NEXT FROM tbl_cursor INTO @tblname
               
        --    END
        --Close tbl_cursor

       
    FETCH NEXT FROM db_cursor INTO @name
END   

--DEALLOCATE tbl_cursor
Close db_cursor
DEALLOCATE db_cursor

--select distinct l.tblName,l.dbName,r.sp_name from StagingData.dbo.ETL0_SearchObjectResults r join StagingData.dbo.ETL0_lkpResults l on r.ID = l.ID order by l.tblName,l.dbName,r.sp_name

 

--SELECT DISTINCT o.name, 'Chr_Utils','ch_ivr_audit'
--From Chr_Utils.dbo.syscomments s JOIN Chr_Utils.dbo.sysobjects o ON s.id = o.id 
--WHERE  s.text like '%ch_ivr_audit%'


--, '+['@name']+','+['@tblname']+

SSRS error log file

C:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\LogFiles

it varies depending on the environment you are working on

 

it details all the error happened on the RS server. Great way for trouble shooting…

Wednesday, September 21, 2011

Code for searching objects among databases and jobs

 

1. Among databases


-- Run on the SVANWARSQL02

DECLARE @SearchString VARCHAR(255)

DECLARE @tblName    VARCHAR(300)      -- each table from  select * from StagingData.dbo.stgETL0Cleanup  delete from StagingData.dbo.stgETL0Cleanup where searchstr ='ch_ivr_audit'
                           
DECLARE @db_name1    VARCHAR(300)
DECLARE @db_name2    VARCHAR(300)
DECLARE @sql        VARCHAR(500)
DECLARE @sql1       VARCHAR(500)
DECLARE @counter    INT
DECLARE @error_num  INT

DECLARE @name VARCHAR(50)

SET @counter = 0
--set @name = 'blabla'
--select searchstr,@name from StagingData.dbo.stgETL0Cleanup

TRUNCATE TABLE StagingData.dbo.ETL0_SearchObjectResults

IF NOT EXISTS(SELECT * FROM StagingData..sysobjects WHERE ID = OBJECT_ID('StagingData.dbo.ETL0_SearchObjectResults'))
   BEGIN
    CREATE TABLE StagingData.dbo.ETL0_SearchObjectResults
        (   
        sp_name                        VARCHAR(300),
        dbName                        VARCHAR(300),
        tblName                        VARCHAR(300),
        ID                            VARCHAR(1000)
        )
    END
   
TRUNCATE TABLE StagingData.dbo.ETL0_lkpResults   
   
IF NOT EXISTS(SELECT * FROM StagingData..sysobjects WHERE ID = OBJECT_ID('StagingData.dbo.ETL0_lkpResults'))
   BEGIN
    CREATE TABLE StagingData.dbo.ETL0_lkpResults
        (   
        dbName                        VARCHAR(300),
        tblName                        VARCHAR(300),
        ID                            VARCHAR(1000)
        )     
   END 
                   
DECLARE tbl_cursor CURSOR FOR
SELECT searchstr
FROM StagingData.dbo.stgETL0Cleanup                   

                                                       
DECLARE db_cursor CURSOR FOR 
SELECT name                 -- get the list of all databases on this server
FROM MASTER.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb','ReportServer','ReportServerExternal','ReportServerExternalTempDB','ReportServerTempDB',
'Strata','TelcoReconciliation','TestForReplication','VanBMCProduction_Backup','MapInfo','RepMD','CommonEvent','CommonEvent_2011Q1',
'CommonEvent_2011Q2','CommonEvent_2011Q3','QuestSoftware','QuestWorkDatabase','ProdAdminDB_Backup','EventData_Detail_cw','Chr_Utils_WrkDB',
'VanReplicaOld'
) 
ORDER by name
   
   
    OPEN db_cursor

 
FETCH NEXT FROM db_cursor INTO @name

While @@FETCH_STATUS = 0
BEGIN
    OPEN tbl_cursor
    FETCH NEXT FROM tbl_cursor INTO @tblname
   
        While @@FETCH_STATUS = 0
            BEGIN   
           
                SET @counter = @counter + 1
                       
                SET @db_name1 =@name+'.dbo.'+'syscomments'
                SET @db_name2 =@name+'.dbo.'+'sysobjects'      
               

                SELECT @sql =                                        
                'SELECT DISTINCT '+'o.name,'+CONVERT(varchar(1000),@counter)+' From '+@db_name1+' s JOIN'+' '+@db_name2+' o ON s.id = o.id '
               
                SELECT @sql = @sql+' WHERE  s.text like '+'''%'+@tblname+'%'''
                --SELECT @sql = @sql+' WHERE  s.text like '+'''%'+@name+'%'''   --->>>>> individual search, change the name between % %
                SELECT @sql ='INSERT INTO StagingData.dbo.ETL0_SearchObjectResults (sp_name,ID)  '+@sql   
                EXEC(@sql)
               
                Select @error_num = @@ERROR               
                IF @error_num <> 0  Print @sql
               
                SELECT @sql1 = 'SELECT '''+@name+''','''+@tblName+''','+CONVERT(varchar(1000),@counter)
                SELECT @sql1 = 'INSERT INTO StagingData.dbo.ETL0_lkpResults(dbName,tblName,ID) '+@sql1
       
                EXEC(@sql1)
               
                Select @error_num = @@ERROR
                IF @error_num <> 0  Print @sql
               
               
                FETCH NEXT FROM tbl_cursor INTO @tblname
               
            END
        Close tbl_cursor

       
    FETCH NEXT FROM db_cursor INTO @name
END   

DEALLOCATE tbl_cursor
Close db_cursor
DEALLOCATE db_cursor

--select distinct l.tblName,l.dbName,r.sp_name from StagingData.dbo.ETL0_SearchObjectResults r join StagingData.dbo.ETL0_lkpResults l on r.ID = l.ID order by l.tblName,l.dbName,r.sp_name

 

--SELECT DISTINCT o.name, 'Chr_Utils','ch_ivr_audit'
--From Chr_Utils.dbo.syscomments s JOIN Chr_Utils.dbo.sysobjects o ON s.id = o.id 
--WHERE  s.text like '%ch_ivr_audit%'


--, '+['@name']+','+['@tblname']+

 

2. Among jobs

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED  -- Instead of use nolock everytime

DECLARE              @Str VARCHAR(100)

DECLARE tbl_cursor CURSOR FOR   
SELECT searchstr
FROM StagingData.dbo.stgETL0Cleanup        stc
WHERE  stc.SearchStr not like 'ch%'

    OPEN tbl_cursor
    FETCH NEXT FROM tbl_cursor INTO @Str
   
        While @@FETCH_STATUS = 0
            BEGIN

                SELECT  @Str = '%' + @Str + '%'

                SELECT                            @str as SearchingName,
                                                CONVERT(VARCHAR(50),jo.name) AS JobName,
                                                jo.enabled,
                                                js.last_run_date,
                                                CONVERT(VARCHAR(30),js.database_name) AS dbname,
                                                CONVERT(VARCHAR(50), js.step_name) AS step_name,
                                                REPLACE(REPLACE(js.command, CHAR(10), ''), CHAR(13), '') AS Cmd,
                                                js.step_id
                FROM    msdb.dbo.sysjobs           jo
                JOIN      msdb.dbo.sysjobsteps js
                ON     jo.job_id     = js.job_id
                WHERE
                    (  jo.name    LIKE @Str
                        OR          js.step_name   LIKE @Str
                        OR          js.command       LIKE @Str
                      )
                                               
                ORDER BY jo.job_id, js.step_id
               
                FETCH NEXT FROM tbl_cursor INTO @Str
       
            END

        Close tbl_cursor
        DEALLOCATE tbl_cursor


SET TRANSACTION ISOLATION LEVEL READ COMMITTED

Monday, July 11, 2011

When open an existing report, BIDS only showed a long line of codes, no actual report layout at all

 

 

It seems that the error message you have provided is a known issue in SQL Server 2008. The issue has been fixed in the latest SQL Server 2008 R2 build.

To solve the issue, please try to remove the code parts: DataType=”Integer” in your xml file, and you can follow

 

Thread: http://social.msdn.microsoft.com/Forums/en/sqlreportingservices/thread/23cb9754-be0e-435c-b2ee-820eb84646c5

#Value! Error on exported Excel file from SSRS rpt

Solution :

  Right click those troubled columns -> choose the text box properties ->  click the Number tab -> highlight number section -> check ‘ Use Regional Formatting’.

This seems to be able to fix the issue

Link: http://social.msdn.microsoft.com/forums/en-US/sqlreportingservices/thread/7aa7f32b-efd5-4f40-914c-ec62f0ee5e0c/

Tuesday, June 7, 2011

Find all stored procedures where a column is being used/referenced

-- compliments from SQLUSA

   1:  USE AdventureWorks2008; 
   2:  DECLARE @SchemaName sysname = N'Production'; 
   3:  DECLARE @TableName sysname = N'Product'; 
   4:  DECLARE @ColumnName sysname = N'ProductID'; 
   5:  SELECT QUOTENAME(refing.referencing_schema_name) + 
   6:  N'.' + QUOTENAME(refing.referencing_entity_name) As SprocName 
   7:  FROM sys.dm_sql_referencing_entities(QUOTENAME(ISNULL(@SchemaName,N'dbo')) + 
   8:  N'.' + QUOTENAME(@TableName),'object') refing 
   9:  CROSS APPLY sys.dm_sql_referenced_entities(QUOTENAME(refing.referencing_schema_name) + 
  10:  N'.' + QUOTENAME(refing.referencing_entity_name), 'object') refed 
  11:  WHERE EXISTS(SELECT * FROM sys.objects 
  12:  WHERE refing.referencing_id = object_id and type ='P') 
  13:  AND refed.referenced_schema_name = @SchemaName 
  14:  AND refed.referenced_entity_name = @TableName 
  15:  AND refed.referenced_minor_name  = @ColumnName 
  16:  ORDER BY SprocName;
  17:   

DATETIME in Store Procedure and Date/Time in Reporting Service

In SP, if you specify only YYYYMMDD and no timestamp, the default one is 0000000. However, in Reporting service parameter section, if the datatype is Date/Time and no time stamp specified, the default one is 125959am. (to be confirmed?)

Monday, May 30, 2011

Report Optimization/Tuning

I have been assigned a task to speed up a slow report. This report actually has 6 different datasets and each calls a different store procedure. My job is to tune it to speed it up. The first step I did is to find out how long it may take to execute the report and associated store procedure to produce the results.

Wednesday, May 25, 2011

Goal for 2011

Currently, the following ideas are floating in my mind:

1. Write at least one quality blog each month

2. Certification on .NET language

3. Own projects need to kick off

4. Contribute more to the Sql Server user Forum

to be added…

Friday, May 20, 2011

Dynamic connection manager in SSIS package, Use DelayValidation = TRUE on pkg level.

Since the connection manager is using the expression to make it flexible, the dataflow will always show the error icon. The tip is to turn the DelayedValidation to TRUE on the package level. In this way, the validation package won’t kick in until the run time.

Thursday, May 19, 2011

unicode and non-unicode data type in sql server 2008

nchar, nvarchar

char, varchar

 

Basically unicode data type requires a bit more space to store than non-unicode datatype. however, it could save you tons of time when it comes to the data type conversion. From the perspective of SSIS ETL processes, lots of source data are in unicode format (excel , dbf) and it would get into the unicode datatype columns a lot easiler than the non-unicode ones.

Can not open a report in the BIDS designer 2008

I am trying to open a report in the BIDS designer. However, it failed to open it and the error xml message is as follows

... Deserialization failed: The 'DataType' attribute is not declared. Line 3102, position 20.....

I’ve posted it to the SSRS social group and also googled around. It turns out as a bug inside VS2008 and the workaround is to manually edit the report xml and strip off all DataType="Integer” inside the <parameterValues> tag.

 

Cheers

Thursday, April 21, 2011

Tips on Remote Desktop Connection

Create a shortcut and in the properties , type /admin or /console, it will connect to the server via Console instead of regular session.

Tuesday, April 5, 2011

Useful article on Reporting Service Maintenance Rpts

On reports maintenance and monitoring

http://www.sqlmag.com/article/reporting2/sql-server-reporting-services-questions-answered

 

Basic idea is to utilize the execution log table inside report server. However , the data in this table will be removed automatically after 60 days. Therefore, you need to run a package from MSFT to move those log data into a separate database and start to report from there.

Monday, April 4, 2011

HL7 pipe counter

Freeware

http://www.comstock-software.com/Blog/?Tag=HL7+Interface

Meditech tricks

Ctrl+F12 : Magic Key menu

Shift+F8: Field name in meditech DPM

Sunday, April 3, 2011

Tether BB Pearl 8130 to Laptop

Step 1; Install the latest Desktop manager which will give you the modem driver

 

Step 2: Click Mobile internet at the bottom left and there you go

 

If you encounter some problem, you may have some issue with the modem. What you need is to download the file called “BlackBerry USB and Modem Drivers_ITA.msi” and install on your laptop. Should be good to go!

 

Heads-up:

My current data plan gives me 500MB from telus, if using tethering, it will become quickly consumed and the catch is here, if you go over 500mb via tethering, they charge $8 per MB.  Better go with a flex data plan if you intend to use mobile internet quite often.

Thursday, March 31, 2011

Freeware HL7 editor

this tool will break down the message into pieces and count the fields for you.

 

From Iatric Systems, Inc. Hats off to them!

Wednesday, March 30, 2011

Tricks in Meditech NMI module

In the View Messages screen, move cursor to the desired message segment and press ctrl-z which brings to the view message segment detail screen. Hit F11 to ext and press ctrl-A which shows the detailed position information on the desired segment.

Friday, March 11, 2011

Connect to dBase file via SSIS

I was tasked to convert a dbase application to a web apps. The first step is to pull data from dBase

 

1. In Connection Managers, New a OLE DB connection by using Microsoft Jet 4.0 OLE DB provider

 

2. On the Server name,  it’s a little bit tricky as you have to put the path instead of the file name. (I got stuck on this part for a few hours!)

 

3. In All property, manually enter dBase II in the Extended Properties ( MS said that, not me!)

 

Test the connection and there you go!

 

Another way is the pull data and dump into an Access table or excel sheet. However, by using SSIS, you can have more flexibility during the ETL process.

 

 

Here is the link from Microsoft on how to connect to dbase or other DBF file

 

http://msdn.microsoft.com/en-us/library/aa337084.aspx

ETL from Sql Server to Access , lesson learned

In destination access table, one column is Yes/No type while there is no yes/no datatype in Sql server.  Int datatype is employed where 0 indicates false and –1 indicates true.

Also in access, all varchar datatype is Unicode WT_WSTR while in Sql server, they are DT_STR. Need to use derived columns between source and target just to convert them.

Wednesday, March 9, 2011

SSMS 2008 can not save comments for SQL Server 2000 tables

I am trying to put some comments for a view in SQL SERVER 2000 but seems not able to do so. However, when I use Enterprise Analyzer to perform the same task, it seems fine. I think SSMS 2008 is not quite compatible with SQL SERVER 2000. Just a small tip to remember.

Wednesday, February 2, 2011

Report with blank pages

I am assigned to a reporting project recently and have encountered this issue. I thought I need to write it down for future reference.

 Problem:

When I developed reports in BIDS, The report looks find in the Designer and report manger. However, when it comes to be exported to as PDF or simply printed out, quite a few blanks pages appeared from nowhere.

Solution:

1. Margin size and body size

This is the first step you need to look into. The following formula may help you calculate the right size

Body width size = Page widthsize - (Left margin + Right margine) – Border width

For example, the page size is defaulted as a letter ( 8.5x11in) and margins are all .25 inch.

In this case, the theoretical body width size <= 8.5-(0.25+0.25) which is 8in. Normally I will give out another .5 inch for buffering.

 

2. CanGrow properties on Textbox

Sometimes, you need to play with this properties

 

3. ConsumeContainerWhiteSpace property on Report level

The default is false. You have to turn it to true in order to remove blank pages

 

I’ll keep posting tips on SSRS . So many tiny things to keep in mind

Thursday, January 6, 2011

Own Side projects

Recently, I am thinking about learning RSS feed technology. A perfect project to hone the skillsets would be pulling housing information from websites like Kijiji and CL via separate RSS feed. Then, mapping those info to the Google map. Should be a very fun yet useful project!

Tuesday, January 4, 2011

AHCI or Compatibility

I’ve purchased a brand new laptop recently during the boxing week sale and am trying to put windows XP on it. I thought it would be an easy job liking walking into the park but when I popped the disk in and it gave me the ugly blue screen death after churning  for a while? Why?  After googling around, the key lies in the Boot manager. I have to enter F2 during rebooting and change the SATA setting to compatible as the default one is AHCI. Lesson learned!