Copy text to clipboard using javascript

Copy & Paste is most common function used among web users. It’s simple in web environment to select text and copy text to clipboard using Ctrl C key but sometimes we may have long text/content in the page which may be output which end user wants to print/copy in text files. In such case, It’s required to provide one button clicking on which it will copy long text to client’s clipboard.

This functionality can be achieved using ¬†window.clipboardData.setData java script method but hold on ūüôā , this is supported in IE and Crome only. This is not working in firefox. Due to security issue, most of the modern browser has depreciated support of this method so the only simple solution is to provide alert message to user that the functionality will work only with IE and Crome if the page is opened in firefox.

There are some other alternatives like using flash object and third party like ZeroClipboard but I like simple solution for any problem so prefer go with first solution which I explained above.

Refer below links for more technical details.

Posted in Uncategorized | Leave a comment

Nice article on Unit Test

Recently we came across situation where we are using session in the controller’s action and we have to write unit test case for that action. Here is nice article which describe different approaches to write test case for this scenario with and without using open source test frameworks like MOQ.


Posted in MVC | Leave a comment


In Oracle there is no support for Identity column which we have in SQL. You have to use Sequence to achieve the same functionality in Oracle.

When we develop the MVC application with Entity Framework which is multi DB supported (Both SQL and Oracle), We have to really think about this issue.

One solution is to use Sequence in both SQL (new feature of SQL 2012) and Oracle with Insert Trigger and use StoredGeneratedPattern attribute for Identity column in DBML file. StoredGeneratedPattern has known issue with VS2010 ( which is resolved in VS2010 SP1.

Second we can write DB function which returns NEXT value from sequence.

select NEXT VALUE FOR  dbo.Student_Sequence

This way we can deal with sequences using entity framework.

Reference Links






Posted in SQL | Leave a comment

SQL Server 2008 – Not able to see my SQL instance in network

I have SQL 2008 Server Express installed on my machine But It was not discoverable in network and this was preventing me to access my sql server instance from another pc.

After goggling I came to know this was because “SQL Browser” service was not started in my machine. Once I started it, I was able to connect my SQL server instance from another machine.

Below is nice link which guide step by step on this issue.





Posted in SQL | Tagged | Leave a comment

Recently we came across one scenario in our project where we have to decide best option to store spreadsheet data in the database.

we have finalized four options and out of those options one is to store the data in XML datatype column.

To check the performance of this option, we decided to create one sample xml file which stores 50000 raw data with 10 columns.

Here is script we used in this scenario.

— table used to insert random data

–CREATE TABLE [dbo].[Table_Data](
—¬†¬† ¬†[Table_Id] [int] NOT NULL,
—¬†¬† ¬†[RowId] [int] NOT NULL,
—¬†¬† ¬†[ColumnId] [int] NOT NULL,
—¬†¬† ¬†[Data] [nvarchar](500) NOT NULL


— Table used to import data

CREATE TABLE [dbo].[XML_Data](
    [XMLDATA] [int] NOT NULL

— 1) Script to insert sample data in sql table

–declare @rows int = 50000
–declare @cols int = 10

–while(@rows > 0)
—¬†¬† ¬†while(@cols > 0)
—¬†¬† ¬†begin
—¬†¬† ¬†¬†¬† ¬†insert into table_data values (1,@rows,@cols, cast(@cols as varchar) + cast(@rows as varchar))
—¬†¬† ¬†¬†¬† ¬†set @cols = @cols – 1
—¬†¬† ¬†end
—¬†¬† ¬†set @cols = 10
—¬†¬† ¬†set @rows = @rows – 1

— 2)¬† Script to count the no of records inserted in sql table

— SELECT COUNT(1) from BOP_TEST.dbo.table_data with (nolock) where rowid >1950000

— 3) create sample xml file from sql table records

— a) enerates xml file from sql table data using BCP

— following commands needs to be executed to enable xp_cmdshell command in sql

–EXEC sp_configure ‘show advanced options’, 1

–EXEC sp_configure ‘xp_cmdshell’, 1

— query which generates xml file from sql table data

–declare @cmd nvarchar(255);

—- Please note that the fully qualified table name is needed
–select @cmd = ‘
—¬†¬†¬† bcp “SELECT * from BOP_TEST.dbo.table_data with (nolock) where rowid >1950000 FOR XML PATH(”DemoModel”), root(”root”)” ‘ +
—¬†¬†¬† ‘queryout “d:\sample.xml” -S DSK-358\SQLEXPRESS -T -w -r -t’;

–exec xp_cmdshell @cmd;

— b) construct xml and output the xml in the output window of sql

–SELECT¬† * from table_data with (nolock) where rowid >1950000
–FOR XML PATH(‘DemoModel’), root(‘root’)

–4) insert the xml file content in the table which has one column as xmltype

–INSERT INTO table_data(data)
—¬†¬† BULK ‘d:\sample.xml’,
—¬†¬† SINGLE_BLOB) AS XmlFileStorage

Posted on by Suril Patel | Leave a comment

Pivoting in SQL

This post has good example of using PIVOT to get the row data in column format.

Here is example created by taking reference of this.

create table #table(tid int,tname varchar(10))
create table #column(cid int,tid int,cname varchar(10))
create table #data(tid int,cid int,dat varchar(10))

insert into #table

insert into #column

insert into #data

declare @Cols nvarchar(max), @SQL nvarchar(max)

SELECT @cols = STUFF ( (SELECT ‘,’ + cname
FROM #column t1
FOR XML PATH(”)), 1, 1, ”)

set @sql= ‘select * from(select cname,dat from #data d inner join #column c on d.cid=c.cid)pp
(max(dat) for cname in(‘+@cols+’))p’

drop table #table
drop table #column
drop table #data




Posted in SQL | Leave a comment

Nuget Package file Issue in visual studio

I have lots of nuget package files added in my current project solution. whenever i was taking get latest of solution, it was taking 5 minutes to ready solution and in the output window, it shows “The item ….. is already exists” for each and every package file i added in my project.

To overcome this issue, I googled and found that this is know issue with nuget package manager 1.7 and solution is to upgrade it to latest version of nuget package manager so I uninstalled nuget package manager 1.7 from my pc and reinstall the latest nuget package manager 2.0.

After this my issue got resolved.




Posted in Common | Leave a comment

Permanently store username and password of TFS in your PC

It was too boring to enter username and password of TFS every time when I want to connect my project to TFS in visual studio (operating system Рwindows 7).  I was not aware how to store this credential information permanently in my PC but yesterday I got the solution for this from one of my college. Here it is.

1) Go to Control Panel\All Control Panel Items\Credential Manager
2) Click on add windows credential
3) Add Internet network add,username and  password  and save it

Now whenever you will connect TFS it will not ask credential information. Enjoy ūüôā

Posted in Common | 2 Comments

Microsoft .NET C# Naming Convention

In my recent project, Everything went smooth but at the end of the project when we delivered code to client, We got comment from client on naming convention.

In code, at few places naming convention for .NET C# coding was not followed hence we had to change it. It’s really good practice to follow naming convention from the beginning of the project. Event if you are working on sample or test project, Try to follow the naming convention and after some time it will become your habit ūüôā

Here is link of guideline provided by microsoft.



Posted in .NET | Tagged , | Leave a comment

ExecuteCore() method in base controller is not firing in the MVC 4 RC

Generally we use BaseController in MVC which is inherited by all other controllers. In BaseController, We write  common code which can be used in the all pages e.g. setting the language in the current thread for multilingual site.

One of my friend migrated his code from MVC3 to MVC4 RC and found that the code written in the ExecuteCore() method of BaseController does not work. After debugging he found that ExecuteCore() method is not executing.

After searching on the net, we found the solution.

To make it work again. following code needs to be added in the BaseController class.

 protected override bool DisableAsyncSupport
                return true;



Posted in MVC | Tagged | Leave a comment