Tuesday, April 30, 2013

How to get open SQL connection of databases

SELECT
DB_NAME(dbid) AS DBName,

COUNT(dbid) AS NumberOfConnections,

loginame AS LoginName,

nt_domain AS NT_Domain,

nt_username AS NT_UserName,

hostname AS HostName

FROM
sys.sysprocesses

WHERE
dbid > 0

GROUP
BY dbid,

hostname,

loginame,

nt_domain,

nt_username

ORDER
BY NumberOfConnections DESC;

Wednesday, April 24, 2013

How to get values between two tags C#

How to get values between two tags C#


 private void df(string htmlTempate,  out int widthPersonal,  out int widthTimeLineLi)
      {
         widthPersonal = 0;
         widthTimeLineLi = 0;
         Regex regexPersonalInfo = new Regex("<widthpersonalstart>(.*)<widthpersonalend>");
         Regex regexTimelineLi = new Regex("<widthtimelinestart>(.*)<widthtimelinend>");
         var v = regexPersonalInfo.Match(htmlTempate);
         if (v.Groups != null && v.Groups.Count > 0) {
            string _widthPersonal = v.Groups[1].ToString().Trim();
            int.TryParse(_widthPersonal, out widthPersonal);
         }
         var v2 = regexTimelineLi.Match(htmlTempate);
         if (v2.Groups != null && v2.Groups.Count > 0) {
            string _widthTimeLineLi = v2.Groups[1].ToString().Trim();
            int.TryParse(_widthTimeLineLi, out widthTimeLineLi);
         }
      }
Where sample htmlTempate is as follows:
 " dasf afadf af adfadf af <widthpersonalstart> 800 <widthpersonalend>  afafadfa a adf af a adf af a adfa<widthtimelinestart>154<widthtimelinend> adfa f af adf adf ads";

Thanks
Mahesh

Wednesday, April 10, 2013

How to get numbes form a string

Suppose you have a string which contains the number and chars and in functionality you only need numeric values.
Than just replace characters with blank values after it you will have numbers only.
we can use RegEx in code.
 Code:string

s = "adsf242343";


int numbersOnly = 0;


Int32.TryParse(System.Text.RegularExpressions.Regex.Replace(s, "[^0-9]+", string.Empty),


out numbersOnly);


Thanks
Mahesh