Rajib Bahar's Blog

Rajib blogs here about topics of his interest.


December 05
by Rajib Bahar 5. December 2013 05:53

I ran my first marathon in October 2012 in "Medtronic Twin Cities Marathon". I finished it in the pace I practiced. It was one of the most memorable milestone of my life. I loved it because I was practicing for that day for about an year. Unfortunately, this wasn't the case when I participated in 2013 marathon. I had to skip few long run practice on saturdays due to various work and extra-curricular committments. In addition, I had bronchitis for over a month. At the time, I thought I had minor cold. Anyways, I ended up receiving antibiotics from the doctor 4 days prior to the race. I had to take the medicine for next 5 days. I knew it wasn't a good idea to do the race. I have seen professional runners backing away from events in the event of an injury or unforeseen setbacks. However, I reasoned if I felt reasonably well then I'll go as far as I can go in that condition. I can tell when my body isn't capable of handling. I just wanted to participate. It's inspiring to see others running with you, event decorations, volunteers cheering for you, and kind people giving you food along the journey. It's the day runners get to meet other runners... The closest analogy to it would be a corporate conference where people aren't sitting down but running. As I started running, I noticed I had some irregular heart beat issue at the first mile... It made my head spin for a while, but, I recovered. When I approached the 13th mile, I felt muscle pull on top of my right knee. I approached EMS people and asked them to give me an ice pack. I continued running after icing the knee area. If I felt discomfort then I iced it while running. This led to another complication few miles down the road. My right shoulder muscle pulled because I was using the right hand to ice the right knee. I tried to adapt and compensate for that situation by using my left arm to ice the right shoulder. Now, you can probably guess where this is leading. My left shoulder muscle pulled. I ran in that condition. I ran so slow that I was barely infront of the truck that's designated as the marathon finisher truck. They pick up runners who are either exhausted or too slow. I earned that distinction that day. I was actually laughing in my mind with pain in my body. The marathon-truck-people asked me whether I wanted to quit around the 21st mile. I ran up to 23rd mile. That's when I threw in the proverbial towel... I wasn't exhausted, but, annoyed at the situation. I shouldn't have ran that day, but, I don't regret participating in that event. I am hoping and planning to participate next year if all goes well. Next year, I'll probably back away at the slightest deviation in training plan or health condition. I have other good running related stories to share. I'll get to it whenever I can. :)

Rajib Bahar Photography

December 02
by Rajib Bahar 2. December 2013 02:31

Last two years, I was doing a lot of running. I enjoyed the camaraderie with our team in eagan. However, this year I found a new hobby which I ran into accidentally. A lot of my family friends started asking me to take pictures at their private gathering... Prior to this, I was using Canon 5d Mark 2 primarily for videography projects for nonprofit organizations I volunteered for. I've been using 5d since it came out. So, I started experimenting with various techniques with DSLR, and photo editing as I attended various events. Along the way, I learned new things from friends who were heavily into DSLR photography. I was invited to cover various large events this year. They include Holi color festival, dance team performances, running events, and nature photography. Anyways, I'll see where this journey will take me. I thought I'd let my friends, colleagues and well wishers know that I launched a website for my photography project. The webpage address is http://www.rajibbaharphotography.com/. Feel free to click the image below to see similar themed unique pictures. Any kind feedback will be greatly appreciated.




Ambarsariya cover song by guests of KFAI Radio Nikita Deval & Anshul Gupta - The Lennie Chism Show

November 23
by Rajib Bahar 23. November 2013 23:30
I volunteer for a minnesota based community radio namely KFAI. During my free time, I love contributing to their world music segment. It is a great privilege to be able to share my cultural heritage and mix it up with Minnesotan cultural scene. Here is a clip from one of the show.

Dance Performance of Thug Le by Bollywood Dance Scene Twin Cities at KFAI Radio with Rajib - The Lennie Chism Show

February 25
by Rajib Bahar 25. February 2013 02:00
I volunteer for a minnesota based community radio namely KFAI. During my free time, I love contributing to their world music segment. It is a great privilege to be able to share my cultural heritage and mix it up with Minnesotan cultural scene. Here is a clip from one of the show.

Is a table variable always the answer?

August 14
by Rajib Bahar 14. August 2012 00:27

I usually got good results with table variables over cursors or derived queries. I wanted to take advantage of available memories. In one of my previous project, I tried to implement an alternative to cursor via table variable. Unfortunately, it caused the SSIS process to run out of memory after running for 8+ hours. I was surprised to see it perform slower than a derived query version of that same query. It was doing a very basic data retrieval function such as selecting the data. After working with our DBA, we discovered that the server didn't have enough memory available during the time of execution (due to high user traffic). The query would slow down after processing few thousands of rows of data. It took some time to work with our colleagues to figure out the most optimal # rows the table variable can handle at any given time. Anyways, we resorted to the derived queries approach for bigger datasets.

Tags: ,


The EXECUTE permission was denied on the object 'sp_ssis_addlogentry'

August 07
by Rajib Bahar 7. August 2012 05:51

I have been lazy about blogging for a long long long time... I thought I'd get back into it again with an error message. Depending upon a project, I either get full-admin privilege or restricted privilege. Both options have merit, but, I prefer more flexibility in anything I do. This particular error message is very trivial. I'll not be breaking any ground by saying the solution is to grant proper permission. We often run into this kind of permission issues whenever dealing with database objects. It happens whenever the user lacks permission to utilize an object. How did I run into this error? I usually prefer storing ssis logging data in a table. One of these days, I'll get motivated to write my own custom solution. Until then I find the built-in logging mechanism sufficient. In most ssis projects, I had the privilege to utilize sp_ssis_addlogentry object. I didn't have to worry about setting that permission. When this issue arose I had to get help from our dba Jimit Mehta. He's a dba-super-hero for our team. As soon as he ran the statement below, my headache was gone. 



grant execute on sp_ssis_addlogentry to [domain_name\user_name]



December 28
by Rajib Bahar 28. December 2010 17:11

I have been quite busy and inactive in my blog. It was a challenging year. My New Year’s Resolution is to do more blogging compared to 2010.


There is an error in displaying error in the error report!

April 15
by Rajib Bahar 15. April 2010 12:07
That was the screenshot of a presentation by Mark Mydland. He is the group manager of the "Visual Studio Team Test". He presented on the topic of Testing in Visual Studio 2010 in the TwinCities .NET User group. His approach to explaining the solution was easy to understand. Just like any good presentation it had elements of humor involving real life settings. He talked about a funny scenario, when someone entered a 0, triggering a division by zero error message, and stopped the propulsion of a ship. He used humor to drill into our head why quality matters.

This is what I learned by attending this event:
  • IntelliTrace is one of the new feature within the Visual Studio 2010 family of products. I believe visual studio 2010 ultimate edition contains this enhancement. This tool brings automated testing capabilities. I asked Mark few basic questions, and he was very kind in response. Just like other debugger in the microsoft environment, this one can start right within the IDE. We can write automated test scripts depicting certain scenarios, or use the recording option as if you are recording a VBA macro. This in turn generates the code files.
  • One can build a lab within the test manager. In the lab, you can have multiple machines. As per Mark, we can have up to 60 machines (or depending upon the environment) tested at the same time.

This is just glimpse of what I have learned today. There is more to it. I have included some helper or reference links for everyone to check out.

Mark's Team Blog is: http://blogs.msdn.com/vstsqualitytools

Blogs recommended by Mark Mydland:
1. Lab Management Team Blog
2. Brian Keller's Blog

Debugging With IntelliTrace

Set Operation trick to generate date data #TSQL2sDay

December 08
by Rajib Bahar 8. December 2009 17:52

Two things that happened today, which motivated me to write this post: 

1. I learned a new trick using set-operation

2. Also today is the day some of my SQL Server colleagues having #TSQL2sDay party


Here is the entry where I learned the trick [http://ask.sqlteam.com/questions/1206/insert-date-value-for-1-year]. 


I have been participating at AskSqlTeam.com lately. One of the recent question was about how to generate date for 1 year. TG had an interesting solution and I did not realize it was set-operation until Kristen set me straight. :) As usual, I was coming up with a iterative solution as opposed to set-based one. Here is the snippet I modified off of TG's code.

create table #myTable 
(dateCol datetime)
declare @i int
SET @i = 0
 datediff(year, dateadd(day, @i,'2010-01-01'),'2010-01-01')=0
    insert #myTable (dateCol)
    select dateadd(day, @i, '2010-01-01')
    SET @i = @i + 1
select * from #myTable

The script above will create about 365 entries containing everyday of the year 2010. 

TG's answer to that problem was:

create table #myTable 
(dateCol datetime)
insert #myTable (dateCol)
select dateadd(day, number, '2010-01-01')
from   master..spt_values
where  type = 'P'and    number < 365
order by number
select * from #myTable


Anyways, my approach above is not the most ideal solution and it will be slow because of the looping. TG had the right idea. Many DB professional create a reference database for their tasks. In this database one may have scripts that can be applied on scheduled jobs and other artifacts that don't belong anywhere else. The solution above can be improved if we create a reference table containing all integers. Let's say we call that table IntValues. I started building that table today and it took more than 6 hours to enter 2 billion numbers. Here is the final draft of what that script would look like.


create table #myTable 
(dateCol datetime)
insert #myTable (dateCol)
select dateadd(day, number, '2010-01-01')
from   DbReference.dbo.IntValues
where  number < 365
order by number
select * from #myTable

Combining SMO and Powershell to Generate SQL Database Schema

December 08
by Rajib Bahar 8. December 2009 10:49

There are times we find the need to generate the database schema. In SQL Server, it can be easily done using the graphical wizards in the Management Studio. I haven't found a way to script it to this day.


However, one alternative solution to this is to combine .NET programmability feature in powershell, and SMO. With this approach you can setup a powershell script job to automate your team's database build process.


Here are some basic assumptions before reading this post:

1. SQL Server 2008 is installed

2. Powershell is installed

3. SMO is in the GAC (Global Assembly Cache) or you know how to register it there

4. AdventureWorks is loaded in the database


Here are the steps I took to generate script against AdventureWorks database:


First of all, I went to management studio and right clicked on the AdventureWorks database to "Start Powershell"


PS SQLSERVER:\SQL\OVERLORD\SQL2K8\Databases\AdventureWorks> [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")

GAC    Version        Location
---    -------        --------
True   v2.0.50727     C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SqlServer.Smo\1...


At this point, the SMO object was loaded using .NET reflection technology. Next we declare $srv variable and assign the local SQL Server 2008 instance to it. Then we assign the AdventureWorks database to the $db variable. The database object has an overloaded method namely Script(). We need to invoke that method to generate the database script. See the output below as the script is run.


PS SQLSERVER:\SQL\OVERLORD\SQL2K8\Databases\AdventureWorks> $srv = new-object("Microsoft.SqlServer.Management.Smo.Server") "(local)\sql2k8"
PS SQLSERVER:\SQL\OVERLORD\SQL2K8\Databases\AdventureWorks> $db = $srv.Databases["AdventureWorks"]

PS SQLSERVER:\SQL\OVERLORD\SQL2K8\Databases\AdventureWorks> $db

WARNING: column "Owner" does not fit into the display and was removed.

Name                        Status          Recovery Model   CompatLvl        Collation
----                           ------          --------------           ---------            ---------
AdventureWorks       Normal          Simple                 100            SQL_Latin1_General_CP1_CI_AS

PS SQLSERVER:\SQL\OVERLORD\SQL2K8\Databases\AdventureWorks> $db.Script()

( NAME = N'AdventureWorks_Data', FILENAME = N'C:\data\MSSQL10.SQL2K8\MSSQL\DATA\AdventureWorks_Data.mdf' , SIZE = 174080KB , MAXSIZE = UNLIMITED, FILEGROWTH =16384KB )
( NAME = N'AdventureWorks_Log', FILENAME = N'C:\data\MSSQL10.SQL2K8\MSSQL\DATA\AdventureWorks_Log.ldf' , SIZE = 18432KB , MAXSIZE = 2048GB , FILEGROWTH = 1638
4KB ) COLLATE SQL_Latin1_General_CP1_CI_AS
    EXEC [AdventureWorks].[dbo].[sp_fulltext_database] @action = 'enable'


The limitation we run with the above approach is that it doesn't include the objects such as tables, stored procedures, and functions in the script. That's why we have to write a loop to iterate all the tables, procedures, checks, primary, functions, etc. Each of those classes have the Script() method and we can invoke them as we need it. 

PS SQLSERVER:\SQL\OVERLORD\SQL2K8\Databases\AdventureWorks> for ($i=0; $i -lt $db.Tables.Count; $i++) {$db.Tables[$i].Script()}

Yes, there are more gotchas. :(


So far, we have looked into resolving this issue using 1 of the overloaded Script() method. The 2nd version of the overloaded method expects ScriptingOptions as one of the parameter. Here is how we would declare them and the options they give us.

PS SQLSERVER:\SQL\OVERLORD\SQL2K8\Databases\AdventureWorks> $sc = new-object("Microsoft.SqlServer.Management.Smo.ScriptingOptions")

Here is a quick list of properties we can set on the $sc (ScriptingOptions) object.

            $sc.AppendToFile = 0;
            $sc.Bindings = 1;
            $sc.Default = 1;
            $sc.DdlBodyOnly = 1;
            $sc.DriAll = 1;
            $sc.DriAllConstraints = 1;
            $sc.DriAllKeys = 1;
            $sc.DriPrimaryKey = 1;
            $sc.IncludeDatabaseContext = 1;
            $sc.IncludeDatabaseRoleMemberships = 1;
            $sc.IncludeHeaders = 1;
            $sc.IncludeIfNotExists = 1;
            $sc.Indexes = 1;
            $sc.LoginSid = 1;
            $sc.PrimaryObject = 1;
            $sc.Permissions = 1;


 Depending upon your need, you can set the target server version, and the output file properties as well.