Thursday, 24 January 2013

ContextSwitchDeadlock was detected


ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context 0x1b7370 to COM context 0x1b74e0 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

Solution:
 Debug -> Exceptions -> Managed Debug Assistants
 untick ContextSwitchDeadlock

Tuesday, 8 January 2013

Compare comma separated values with comma separated values in sql


CREATE 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 or @String is null  return
   
        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
--function end
GO

--now check below sample
--table variable to hold data
declare @table table
(
        id int,[key] varchar(100)
)
insert into @table
select 1,'session, state' union all
select 2,'a,b,c' union all
select 3,'hi, hello'

--parameter value
declare @data varchar(1000)
set @data='b,c'

--select query to find data
select distinct id
from @table
CROSS APPLY dbo.Split(strkeywords,',') AS AA
CROSS APPLY dbo.Split(@data,',') AS BB
WHERE AA.items=BB.items

Thursday, 3 January 2013

Export Data from Excel files with special characters


Dim grd1 As New GridView()
grd1.DataSource = dt ' dt is Data Table
grd1.DataBind()

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", "attachment;filename=products.xls")
Response.Charset = ""

Response.ContentEncoding = Encoding.Unicode
Response.BinaryWrite(Encoding.Unicode.GetPreamble())

Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
grd1.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()

Tuesday, 18 December 2012

xmldocument.selectnodes not working

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:thr="http://purl.org/syndication/thread/1.0">

  <title type="html">StackOverflow.com - Questions tagged: c</title>
  <link rel="self" href="http://stackoverflow.com/feeds/tag/c" type="application/atom+xml" />
  <subtitle>Check out the latest from StackOverflow.com</subtitle>
  <updated>2008-08-24T12:25:30Z</updated>
  <id>http://stackoverflow.com/feeds/tag/c</id>
  <creativeCommons:license>http://www.creativecommons.org/licenses/by-nc/2.5/rdf</creativeCommons:license>


  <entry>
    <id>http://stackoverflow.com/questions/22901/what-is-the-best-way-to-communicate-with-a-sql-server</id>
    <title type="html">What is the best way to communicate with a SQL server?</title>
    <category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="c" />
    <category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="c++" />
    <category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="sql" />
    <category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="mysql" />
    <category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="database" />
    <author>
      <name>Ed</name>
    </author>
    <link rel="alternate" href="http://stackoverflow.com/questions/22901/what-is-the-best-way-to-communicate-with-a-sql-server" />
    <published>2008-08-22T05:09:04Z</published>
    <updated>2008-08-23T04:52:39Z</updated>
    <summary type="html">&lt;p&gt;I am going to be using c/c++, and would like to know the best way to talk to a MySQL server.  Should I use the library that comes with the server installation?  Are they any good libraries I should consider other than the official one?&lt;/p&gt;</summary>
    <link rel="replies" type="application/atom+xml" href="http://stackoverflow.com/feeds/question/22901/answers" thr:count="2"/>
    <thr:total>2</thr:total>
  </entry>


</feed>



To Get select node

  XmlDocument doc = new XmlDocument();
  XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
  nsmgr.AddNamespace("atom", "http://www.w3.org/2005/Atom");
 doc.Load(feed); 
            // successful
  XmlNodeList itemList = doc.DocumentElement.SelectNodes("atom:entry", nsmgr);


xmldocument load ignore dtd -c#


<!DOCTYPE bibdataset PUBLIC
  "-//ES//DTD abstracting and indexing DTD version 5.12//EN//XML"
  "ani512.dtd">



XmlDocument xmlDoc = new XmlDocument();

 xmlDoc.XmlResolver = null;

convert html entity hex to string c#


string Text=Server.HtmlDecode("Paulo Cesa&amp;#x0301;r");

Output:
Paulo Cesár



Monday, 17 December 2012

sql - Count No. of space in a string


select len('this is for test') - len(replace('this is for test', ' ', ''))

Result:
3