ASP.NET Cafe
new tricks every week

MS SQL 2005 Performance tip: Turn off autoclose for your databases

Wednesday, 25 November 2009 08:40 by dmitriy
MS SQL 2005

For some reason by default you can have "AUTOCLOSE" property of your database set to ON. That's not bad, but if you check your server Event Log you can find a lot of entries like "Starting database 'xxxxxxx' ". And log is not a problem, but for sure this takes a time and slow down your asp.net application response.

You can turn it off in Managment Studio.
or you can run a little sql to update all databases on server:

EXECUTE sp_MSforeachdb
'
IF (''?'' NOT IN (''master'', ''tempdb'', ''msdb'', ''model''))
   EXECUTE (''ALTER DATABASE [?] SET AUTO_CLOSE OFF WITH NO_WAIT'')
'

All databases won't close automatically and response instantly.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   SQL
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

How to Speed up aspnet_compiler

Monday, 16 November 2009 21:49 by dmitriy

Here is one trick to greatly speedup asp.net compiler. First of all, assume you have enough RAM to give about 512Mb for this. RAM is cheap, so you always can visit store and buy it. And your time is priceless. 

Idea is in creating RAM drive and pointing asp.net compiler temp there. To create RAM drive you need to download following free software

http://www.ltr-data.se/opencode.html#ImDisk

IMDisk - awesome thing. Install it.

Now create ramdrive.cmd somewhere ( for example c:\ramdrive.cmd ) with following content

imdisk -a -s 512Mb -m R: -p "/fs:ntfs /q /y"  

create a shortcut and add it to Startup

Now everytime you start PC you'll see quick console window and you'll got a new drive "R"

Ok. Now you need to change your temp settings

Edit this file: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config  

( I assume that you've Windows installed in C:\Windows . Change path if it's different )

 In this file you need to add attribute to <compilation> tag

After change it should look like this: 

        <compilation tempDirectory="r:/asp.net_temp" > 

That's all. Now you can build your asp.net projects much faster. You can try to point all windows Temp on that RAM drive, but I haven't gone this far yet. 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   ASP.NET | Main
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (1) | Comment RSSRSS comment feed

SQL: Finding duplicates in table

Saturday, 14 November 2009 06:55 by dmitriy

Looking for rows with some duplicate values in some column(s) is very common. I'm not saying that's something hard.  I was asked about this. Here is the solution.

 

   1:  SELECT [Name], COUNT([Name]) as NumOccurrences 
   2:  FROM [People]
   3:  GROUP BY [Name]
   4:  HAVING ( COUNT( [Name] ) > 1 )
 

And the query to get all PKs ( primary keys ) for rows with duplicate [Name]:

   1:  SELECT [uid] 
   2:  FROM [People] 
   3:  WHERE [Name] IN (
   4:  SELECT [Name]
   5:  FROM [People]
   6:  GROUP BY [Name]
   7:  HAVING ( COUNT([Name]) > 1 ))

That's all.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   SQL
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Enter button and several inputs

Thursday, 2 July 2009 09:43 by dmitriy
In ASP.NET you have sometimes a problem. When you have several inputs (textboxes) and several buttons. You want user to submit it by hitting enter. For example one login box, one search box. You want to submit login box when user hits enter in password field, and search button when user hits enter in search field. The solution is easy! Just put controls inside the asp:panel with attribute DefaultButton="ButtonFind"  ( where ButtonFind is ID of desired default button ). That's all! It works!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   ASP.NET
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

BlogEngine.NET Theme - Fruity

Tuesday, 3 March 2009 06:42 by dmitriy

Hello everybody!

I've recently finished a new theme for BlogEngine.NET.

 

Fruity theme by S.D. ( aspnetcafe.com )

You can download zip here:

fruity.zip (51,19 kb)

Just unpack it to your themes folder. It works with 1.4.5.0.

That's all for today. 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   BlogEngine.NET
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

H.264 vs VP 6 in hd online video

Monday, 2 March 2009 10:00 by dmitriy

What's better for your online video?

VP 6 is faster ( works on most pcs ) and requires only flash player 8. 

The BAD side of VP6 - it's hard ( or even impossible ) to find free (opensource) encoding solution for it. You need to ask on2.com guys to give you their framework or for personal use you can buy something like "Flix Standard" for $39. That's really nothing even for poor blogger.

H.264 is slower. Only last fast pcs can run it without delays. For example, I've old Celeron 2.4 and it can't handle h264, but good with vp6. But my Core2duo is good with h.264. Another problem of h264 is loosing of smoothness on low bitrate. Picture is quite good, but action is not... if you encode 1280x720 with 1Mbit/s bitrate you can see the problems with slow zooms... it jumps. Usually you can play with complicated settings, but in the end it does not matters. The good enough bitrate for h.264 if you are using 1280 x 720 is about 2-3 Mbit/s.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   Flash | Main
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

MailEnable - How to add new mailbox from code

Tuesday, 10 February 2009 03:49 by dmitriy

Mailenable is quite good Mail Server for windows. It has a free version ( and that's version works good if you don't need WebMail ).

Here is some code to add mailbox to PostOffice.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   ASP.NET | C# | Main
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

How to remove IE 6 background flicker

Monday, 26 January 2009 03:14 by dmitriy

I know one thing that makes cranky all web developers who still support IE 6. Usually we can hope that soon IE 6 became history ( maybe Windows 7 will be so good... and everybody use it and new IE ). But yet many designers still support IE 6. Main trouble that IE does not cache CSS background images. And that's why you see "flicker" effect on reload of you well formed css sites. To get rid of this try to add this script somewhere in the HEAD section... 

 

[code=js]

try

{document.execCommand('BackgroundImageCache', false, true);}

catch(e)

{}[/code]

 This works for me.

ps: You can see this effect good in AJAX.NET Tabs control. http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Tabs/Tabs.aspx

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   ASP.NET
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

MS SQL. How to get only date from datetime field

Tuesday, 4 November 2008 09:25 by dmitriy
And another quick tip for SQL. Sometimes we need to remove TIME part from DATETIME. For example need to group by date or so. You know your needs better.
 
Here is my solution. 
DATEADD(day, DATEDIFF(day, '20000101', RecDate), '20000101')
 
I saw some freaky CASTs and I don't like these. This returns DateTime type, not string. 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   SQL
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

MS SQL. Get rows in random order.

Monday, 15 September 2008 06:42 by dmitriy

During web development often task is to get some stuff in random order. For example, to display random articles, products, testimonials and so on.

First thing you want to do is to write something like this:

SELECT TOP 10 * 
FROM Articles 
ORDER BY RAND() 

And previous query DOES NOT work. It shows records in regular order. Why? Because RAND() calculated once, not in each row.

The following way works fine:

SELECT TOP 10 * 
FROM Articles 
ORDER BY NEWID() 

That's all. Nice and easy. Not recommended for HUGE tables... but this is crazy to try show something randomly from the huge table. Use other ways. For example sub queries.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   Main | SQL
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Google Chrome fails ACID 3 test and pass ACID 2

Tuesday, 2 September 2008 10:03 by dmitriy

We used this test to try IE 8 sometime ago... it failed. 

http://acid3.acidtests.org/

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   Google | Main
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Google Chrome Beta Available For Download

Tuesday, 2 September 2008 09:27 by dmitriy

 

 Woo Hoo! Just get it!

http://www.google.com/chrome

Fisrt impression - very fast...

 More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   Main
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

23 august FFMPEG Win32 build (updated)

Wednesday, 27 August 2008 06:31 by dmitriy

 

If you don't know what is FFMPEG... you possible don't need this.

Or can check out http://ffmpeg.mplayerhq.hu/ 

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   Main
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

ASP.NET 2.0 Big files upload on IIS 6.0 under Win2003

Saturday, 2 August 2008 06:21 by dmitriy

Recently faced the big problem with big files. Not so big, just needed to post files with size about 10-20MB to aspx page. With usage of quite standard control on the page.

Everybody know ( if not - I notice here ) that in web.config you have HttpRuntime settings. And one of these settings is  maxRequestLength .In theor, after adding of this line to web.config file everything should work fine.

 <httpRuntime maxRequestLength="100000"/>

But in fact you can face the problem of limit in IIS. And this is a pain in the ass. Because you need to edit Metabase.xml on server. Sometimes this can be impossible, but sometimes you can do this yourself or ask support. Here is some insturctions to make big files uploads work for you.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   ASP.NET
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Better call for NotifyScriptLoaded in AJAX

Sunday, 27 July 2008 09:54 by dmitriy
Already on Bora bora ? I'm not...

Recently found one thing. Perhaps in docs for AJAX client or somewhere else was such line:

Sys.Application.notifyScriptLoaded(); 

You need to write this line at the end of your JS files. But this can cause the problems if you wish to re-use this code in non-ajax enviroment. For this better to use following line:

if (typeof(Sys) !== 'undefined')  Sys.Application.notifyScriptLoaded(); 

This makes things a bit better. Also, it answers another question - "Testing for defined variables in Javascript".  Sometimes I see the code like:

if( Sys )...  // And this will fail in case Sys is undefined. 

 That's all for now, it's summer. Everybody enjoy their resort life. But I'm still working.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   ASP.NET
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

ForceWrap or when you need a whitespace

Sunday, 8 June 2008 07:08 by dmitriy

Sometimes on websites with user content you can find some design issues because of their content. Actually, I'm about the stuff like

"Swimming*Skimboaring*AquaFitness*Snorkeling*Kayaking*Basketball*Archery*Volleyball*Soccer*Table Tennis*Mini Golf*Badminton*Rock Climbing* Kiteboarding*Fencing*Gymnastics*Yoga*Pilates*"

But we ( as developers want to get rid of such ugly stuff that moves across the bounds of area and can't be wrapped - because there are no white-space inside.

For this I just written force wrap function. It is quite simple, using regular expressions

[code=cs] protected static string ForceWrap(string aStr,int max)
        {
            Regex LongLine = new Regex(@"(?<long>\S{"+max.ToString()+",})");
            MatchCollection matches = LongLine.Matches(aStr); // find all matches of "Long Strings" //
            if (matches.Count > 0)
            {
                StringBuilder sb = new StringBuilder(aStr);
               
                for (int i = 0; i < matches.Count; i++)
                {
                    string s = matches[i].Groups["long"].Value;
                    string origS = s;
                    int segments = s.Length / max;
                    for (int j = 1; j < (segments+1); j++)
                    {
                        int pos = j * max + (j-1);
                        s = s.Insert( pos , " "); // Insert Space //
                    }
                    sb.Replace(origS, s);
                }
                aStr = sb.ToString();
            }
            return aStr;
        }[/code] 

 

First parameter - the string you want to output, the second - max lenght is chars. Return value is new string with whitespace inserted if needed.

I think this is useful, but if there are something better, please let me know. 

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   ASP.NET | C#
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Google maps for Flash (Flex) API

Saturday, 17 May 2008 09:03 by dmitriy

Good news from Google Maps team again. Recently I've found api for Flex. This is a great advantage for actionscript developers. First of all, I've already mentioned that JS api is a bit slow thing... And specially I though about Flex/Flash maps API ( like Yahoo maps provided before ). And right now we have it.

At the first look not so "super" like JS api. But this is a big hit, I think.

  More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Google
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Google maps: Static maps

Friday, 16 May 2008 09:06 by dmitriy

Google maps one of the best mapping API. But sometimes you don't need navigation, zoom and other cool stuff. Sometimes you need something simple. Simple and fast. Yes, google maps makes a page a bit slowly, a bit big, just because this is maps. Looks like guys from Google understood this. Sometimes you don't want to load all the tiles and JS API. You just need to show some address or route on the map. And here static maps can help you. Static map can show simple markers and even routes.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Google
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Credit Card number validation in C#. Visa and MC.

Monday, 12 May 2008 12:25 by dmitriy

Credit card numbers are full of magic. First of all not every 16 digit is CC number, but only by number you can know the issuer. So no need to place on the web form "Visa" / "MasterCard" radio button. Ok, so what's interesting. I found two great articles that helped me with this:
http://www.merriampark.com/anatomycc.htm and http://www.beachnet.com/~hstiles/cardtype.html .

And what now ? I just finished small helper class to validate Credit Cards. Here is the source.

[code=csharp]public enum CCType
    {
        VISA, MC
    }

    /// <summary>
    /// Credit card validation.
    /// Supports : VISA and MasterCard
    /// Reference: http://www.merriampark.com/anatomycc.htm
    /// Contains LUHN (mod 10) check
    /// by D.S.
    /// http://aspnetcafe.com
    /// </summary>
    public class CreditCardValidator
    {
        protected string _CardNumber = "";

        public CreditCardValidator(string aCardNumber)
        {
            _CardNumber = aCardNumber.Replace(" ","").Replace("-","");
            ProcessValidation();
        }

        protected bool _IsValid;

        public bool IsValid
        {
            get { return _IsValid; }
            set { _IsValid = value; }
        }

        private CCType _CardType;

        public CCType CardType
        {
            get { return _CardType; }
            set { _CardType = value; }
        }
       
        protected void ProcessValidation()
        {
            bool passRegEx = false;
            bool passIssuer = false;
            bool passLuhn = false;
            IsValid = false;

            do
            {
                // Reg Ex check //
                Regex RegExNumber = new Regex(@"(?<firsttwo>(?<firstone>\d)\d)\d{11,14}");
                Match m = RegExNumber.Match(_CardNumber);
                passRegEx = m.Success;
                if (!passRegEx) break;
                string number = m.Groups[0].Value; // only digits //
                string firstNum = m.Groups["firstone"].Value;
                int firstTwoNum = int.Parse(  m.Groups["firsttwo"].Value );
                passIssuer = (firstNum == "4") || ((firstTwoNum >= 51) && (firstTwoNum <= 55));
                if (!passIssuer) break;
                if (firstNum == "4") CardType = CCType.VISA;
                if ((firstTwoNum >= 51) && (firstTwoNum <= 55)) CardType = CCType.MC;
                // Now make Luhn check //
                passLuhn = LuhnCheck(number);
                if (!passLuhn) break;
                //
                IsValid = true;
            } while (false);          
        }

        /// <summary>
        /// Performs mod 10 check
        /// </summary>
        /// <param name="cardNumber">Card Number with only numbers</param>
        /// <returns></returns>
        protected bool LuhnCheck(String cardNumber)
        {
            int sum = 0;
            int digit = 0;
            int addend = 0;
            bool timesTwo = false;

            for (int i = cardNumber.Length - 1; i >= 0; i--)
            {
                digit = int.Parse(cardNumber.Substring(i, 1));
                if (timesTwo)
                {
                    addend = digit * 2;
                    if (addend > 9)
                    {
                        addend -= 9;
                    }
                }
                else
                {
                    addend = digit;
                }
                sum += addend;
                timesTwo = !timesTwo;
            }

            int modulus = sum % 10;
            return (modulus == 0);
        }
    }[/code]

The code is quite simple. But works good for me. I'm not providing you with a sample application, you know there are my credit card number :)

Check the articles at the top of the page if you want to know how it's works. And what is Mod 10 check.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   ASP.NET | C# | Main
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Some notes about your video for the web

Wednesday, 7 May 2008 12:26 by dmitriy

Recently faced the problem to quickly insert video inside web page. Here are the things I found and you need if you wish to start with that deal.

First of all, we are going to insert FLV video. But sources in avi or m4v, mov... To convert them we need some kind of converter. Awesome project FFMPEG is best for this. Binaries for windows here: ffmpeg.rev12665.7z (2.46 mb)
Frankly, I forgot the URL to download this, but this file is unchanged.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Main
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed