Thursday, December 27, 2012

No Object Exist with Lineage ID of XXXX in SSIS


Please click below link
1) when you migrate your SSIS package to SQL higher version
2) place square brackets around column name in SUBSTRING function

see below link

click here



done.

Simple C# code to get Quarters

 public static DateTime GetQuarterStartDate()  
     {  
       DateTime date = DateTime.Today;  
       int quarterNumber = ((date.Month - 1) / 3) + 1;  
       return new DateTime(date.Year, (quarterNumber - 1) * 3 + 1, 1);  
     }  

Friday, November 16, 2012

svchost.exe process consume CPU memory with "winrscmde" description



If  you feel your computer is very slow.  Some time you get BLUE screen in your Windows 7 OS.
Please check following things:
1) hit Ctrl + Shift + Esc to open task manager.
2) Click "Processes" tab.
3) Sort by "Memory" > higher memory first
4) check if any services running with "svchost.exe" image & "winrscmde" as description
and conusming lots of CPU memory.


Solution:

download TDSKiller.exe from CNET > Install & Scan your computer


http://download.cnet.com/Kaspersky-TDSSKiller/3000-2239_4-75722087.html 


More details:

http://www.bleepingcomputer.com/forums/topic436219.html
http://forums.spybot.info/showthread.php?t=66455




thx

select column in PDF, Vertical test select in pdf



hold Alt key and then select PDF column it will select vertical.


Friday, November 9, 2012

Cannot add an entity with a key that is already in use, LINQ


-- When you get above error there are two possibility

1) you are trying to insert duplicate primary key.
2) when you have SQL column with data type = "Uniqueidentifier" and default set to 'NewID()'
    that means its auto-generated field.

   Make sure in you DBML file that tale > field > properties > "Auto Generated Value"  is set to true
   default is fault

Monday, October 15, 2012

Operand type clash: int is incompatible with uniqueidentifier



When you get above error please double check following

- you are inserting into table from view
- table has column with data type - uniqueidentifier  with allow null
- view is returning null for uniqueidentifier field
- you have to convert null to uniqueidentifier field in view 

for example ,convert(uniqueidentifier,null) as MyUniqueIdentifierField  

Tuesday, October 2, 2012

Autogenerate get and set class properties



1) use  notepad ++ to generate class private properties
2)
You can right-click on the field and go to Refactor > Encapsulate Field. That will generate a public Property. You still have to do each one at a time but it's a lot faster than the typing!

Thursday, September 27, 2012

sqlbulkcopy with transaction



string connstring = _hsconnstring.Substring(1, (_myconnstring.Length - 1));
using (SqlConnection destinationConnection = new SqlConnection((connstring)))
{
    destinationConnection.Open();

    using (SqlTransaction transaction = destinationConnection.BeginTransaction())
                {

                    using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection,SqlBulkCopyOptions.Default,transaction))
                    {
                        try
                        {
                            bulkCopy.DestinationTableName = "myfirsttable";
                            bulkCopy.WriteToServer(outTable1);
                           
                            bulkCopy.DestinationTableName = "mysecondtable";
                            bulkCopy.WriteToServer(outTable2);

                            bulkCopy.DestinationTableName = "mythirdtable";
                            bulkCopy.WriteToServer(outTable3);

                            bulkCopy.DestinationTableName = "myfouthtable";
                            bulkCopy.WriteToServer(outTable4);
                           
                            bulkCopy.DestinationTableName = "myfifthtable";
                            bulkCopy.WriteToServer(outTable5);
                            bulkCopy.Close();
                            transaction.Commit();

                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                            Utilities.HandleError("Error at data bulk insert: ", ex);
                            throw ex;
                        }

                    }
                }

            }

number of current open sql session using query


--SP
exec sp_who




--QUERY
SELECT
    DB_NAME(dbid) as DBName,
    COUNT(dbid) as NumberOfConnections,
    loginame as LoginName
FROM
    sys.sysprocesses
WHERE
    dbid > 0
GROUP BY
    dbid, loginame
    order by DB_NAME(dbid)

Monday, September 24, 2012

SQL create split function and how to use function in sql



ALTER FUNCTION [dbo].[Split](@String varchar(8000), @Delimiter char(1))      
returns @temptable TABLE (items varchar(8000))      
as      
begin      
    declare @idx int      
    declare @slice varchar(8000)      
     
    select @idx = 1      
        if len(@String)<1 br="br" is="is" nbsp="nbsp" null="null" or="or" return="return" tring="tring">     
    while @idx!= 0      
    begin      
        set @idx = charindex(@Delimiter,@String)      
        if @idx!=0      
            set @slice = left(@String,@idx - 1)      
        else      
            set @slice = @String      
         
        if(len(@slice)>0) 
            insert into @temptable(Items) values(@slice)      
 
        set @String = right(@String,len(@String) - @idx)      
        if len(@String) = 0 break      
    end  
return      
end 
GO


--- How to call the function

select * from [dbm].[Split] ('L196,L201,L197',',')