none
best practices with types for optimal performance RRS feed

  • Question

  • I am not sure that this is the best forum to post this in. There seems to be some overlap on this subject. I have recently done a little reading on sql server optimization.

     

    I am wondering what the best practice is for choosing datatypes in a C# project that will be writing to a sql server 2005

    database. This is the conclusion that I have made from reading a couple articles. Though none of the articles said this explicitly. This is why I am looking for a correction or a confirmation.

     

    I should carefully choose the types in order to get the best performance from my app. This should be done for both my C# and Sql Server data types. Careful consideration should be given when deciding what types to use. Both the SqlServer and C# types should be ones that are the most similar in type and size.

     

    This is should be done to maximize performance. This will be achieved by reducing the number of implicit and explicit conversions that need to be done. It will also enable the most efficient allocation of memory. Is this correct?

     

                                                                        -thanks

     

     

    Sunday, January 20, 2008 5:43 PM

All replies

  • Hi,

    Not only this but you have to be careful about the conversions also. Like you should use Convert.ToDecimal instead of CDec as it is newer and render more performance. As a matter of fact, try to ignore all of them (CInt, CDec, CStr etc.)

     

    Regards

    Rajeev

    Sunday, January 20, 2008 7:14 PM
  • Hello,

     

    That's exact because CInt,CDec,CStr are VB reserved words.

    In any case, it's always better in VC# to use :

    Convert.ToString(...),Convert.ToInt32(...) and so on

    or

    Int32.TryParse,DateTime.TryParse() and so on

    Try this excellent post

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2674122&SiteID=1

     

     

    Have a nice day

    Monday, January 21, 2008 10:33 AM