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.

http://solvedstack.com/questions/jquery-click-button-copy-to-clipboard

http://help.dottoro.com/ljctuhrg.php

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.

http://stephenwalther.com/archive/2008/07/01/asp-net-mvc-tip-12-faking-the-controller-context.aspx

 

Posted in MVC | Leave a comment

ENTITY FRAMEWORK WITH SEQUENCE FOR INSERTS

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 (http://blogs.devart.com/dotconnect/entity-framework-tips-and-tricks-part-4.html#fourth) 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

1) http://shanthuk.com/2012/08/26/entity-framework-oracle-indentitysequence-for-inserts/

2) http://www.ladislavmrnka.com/2011/03/the-bug-in-storegeneratedpattern-fixed-in-vs-2010-sp1/

 

 

 

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.

1) http://www.linglom.com/2009/03/28/enable-remote-connection-on-sql-server-2008-express/

2) http://kristofmattei.be/2009/10/25/sql-server-2008-express-edition-access-over-network/

 

 

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
–) ON [PRIMARY]

–GO

— 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)
–begin
—¬†¬† ¬†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
–end

— 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
–RECONFIGURE

–EXEC sp_configure ‘xp_cmdshell’, 1
–RECONFIGURE

— 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;
–go

— 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)
–SELECT * FROM OPENROWSET(
—¬†¬† 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.

http://beyondrelational.com/modules/2/blogs/88/Posts/14196/changing-rows-to-columns-using-pivot-dynamic-columns-for-pivoting-in-sql-server.aspx

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
values(1,’t1′),(2,’t2′)

insert into #column
values(1,1,’c1′),(2,1,’c2′),(3,1,’c3′)

insert into #data
values(1,1,’ss’),(1,2,’pp’),(1,3,’aaa’)

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
pivot
(max(dat) for cname in(‘+@cols+’))p’
exec(@sql)

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.

http://msdn.microsoft.com/en-us/library/ms229002%28VS.100%29.aspx

 

 

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
        {
            get
            {
                return true;
            }
        }

 

 

Posted in MVC | Tagged | Leave a comment