Tuesday, June 5, 2012

SignalR

SQL Server Indexes

Clustered Index
Non-Clustered Index
Composite Index
Unique Index  (Automatically gets created when you create primary key or unique constraint)
Covering Index


asp.net mobile

some random notes about mobile development from asp.net videos of scott hansleman


  1. Add a view port meta tag       <meta name ="viewport" content = "width=device-width">
  2. Fix it on the client
    • custom css
    • media css
    • adapative rendering
  3. Changing unordered list to dropdown as width is reduced .. use opt group of html 
  4. Dynamically change based on screen size  mediaqueri.es
  5. Fix it on the Client
    1. Pros 
      1. optimized for the current size
      2. less duplication of efforts
    2. Cons
      1. doesn't consider the differences between mobile and desktop
      2. inefficient bandwidth usage
  6. Fix it on the server
    1. custom mobile views using display modes
    2. jquery mobile (comes with asp.net mvc 4)
    3. Make new page with new scripts and css for the mobile page
    4. Mobile Master Page
    5. Mobile Child page
    6. data-role = "content".. tell html5 elements and jquery mobile takes care of the look it has to appear
    7. data-theme .. can be downloaded from jquery mobile ..
    8. jquery.mobile.mvc .. nuget package .. 
    9. view switcher .. (mobile version to desktop version & vice versa)
    10. Ctrl + , to find code or navigate in visual studio ..
    11. jquery mobile can do data filtering .. 
    • Pros
      • maximum flexibility
      • less duplication of efforts
    • Cons
      • can be repetitive
      • device detection can be hard
  7. Jquery Metro Mobile Theme
  8. 51degrees.mobi (nuget packaage available)
  9. Web Sites vs Web Applications
    1. Offline Capability
    2. knockout.js for data binding
    3. static resources for caching .. as cache manifest 


Monday, March 19, 2012

TSQL to LDAP


Script using Master table to create the Link – Step 1
EXEC master.dbo.sp_addlinkedserver @server = N'ADSI', @srvproduct=N'Active Directory Service Interfaces', @provider=N'ADSDSOObject', @datasrc=N'adsdatasource'
GO
EXEC master.dbo.sp_serveroption @server=N'ADSI', @optname=N'collation compatible', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'ADSI', @optname=N'data access', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'ADSI', @optname=N'dist', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'ADSI', @optname=N'pub', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'ADSI', @optname=N'rpc', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'ADSI', @optname=N'rpc out', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'ADSI', @optname=N'sub', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'ADSI', @optname=N'connect timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N'ADSI', @optname=N'collation name', @optvalue=null
GO
EXEC master.dbo.sp_serveroption @server=N'ADSI', @optname=N'lazy schema validation', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'ADSI', @optname=N'query timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N'ADSI', @optname=N'use remote collation', @optvalue=N'true'
GO

Step 2 – Set to Domain Admin account

Then Query

SELECT *
FROM OPENQUERY(ADSI,
'SELECT mail
FROM ''LDAP://DC=orgname,DC=org''
WHERE objectCategory = ''Person''
AND objectClass = ''user''
AND sAMAccountName = ''***''')


Tuesday, March 13, 2012

SSRS URL parameters


This article shows you some of the most common reporting parameters to use in Microsoft SQL Server Reporting Services.
When you go to the [http://reportserver/reportserver/foldername/reportname]
The last command in the url is &rs:Command=Render
You can add some other commands as follows:
&rc:Parameters=Collapsed 
  • This collapses the parameter bar but sends the parameters in the URL in the browser
  • &rc:Parameters=true 
  • This shows the parameter bar and is the default
  • &rc:Parameters=false 
  • This prevents the parameters from being passed in the browser and expanded
  • &rc:toolbar=false 
  • This hides the toolbar
  • &rc:format=PDF 
  • This will open up the report as a PDF
  • &rs:Format=EXCEL&rc:OmitFormulas=true 
  • This will open the report in Excel
  • rs:ClearSession=true 
  • This clears the session state for the user. Used where the caching of the report prevents the designer from seeing their updated report and/or data.

  • * This is a very important parameter to know as more often than not, the report data doesn't update immediately unless parameters are changed, and your report may show cached data if this is not set.&rc:StyleSheet=MyCustomStyle 
  • Note don’t add the .css extension. And this style sheet must be in the folder Program FilesMicrosoft SQL ServerMSSQLReporting ServicesReportServerStyles folder.

  • Use the HTMLViewer.css as your base template.
  • ReportServer Parameters:
    If you add ?/FolderName/ReportName after the [http://servername/reportserver] you can run the report.
    The same applies if you want to list the reports, then just type ?/FolderName after the [http://servername/reportserver].
    This is commonly used when the user only has permissions at the folder level, not the root level. 

    Sunday, February 12, 2012

    State Pattern

    I am learning about design patterns in depth these days. Amazed by the solutions they give .. Some patterns like abstract factory , factory made sense to me but could not find immediate application to my code .. so could not get that uahaa feeling ;) When i read about the state pattern http://blog.raffaeu.com/archive/2011/02/13/state-pattern-using-c-part-01.aspx .. i found an immediate use for this in all my code. I realized how my code is tightly coupled all these days .. Implemented this and now i have a happy feeling .. I learned something new and implemented it . .................. :) :)

    I have a class which as states such as new edit view .. I moved all the logic related to this states using this pattern :)

    Friday, February 3, 2012

    Hidden Field in a disabled panel or div

    I was working on a form for a project. The form needs to be edited or viewed. For view i disabled all the panels or divs.But it has some links which needs to work. The links used hidden fields inside the disable panel.
    Then i sudden found the links are not working as the hidden fields are not retaining the values as they normally do. Then a google search on this gave me this link .. which saved my time a lot.. It seems asp.net does not maintain view state for hidden fields in a disabled panel. So need to get around this by some way :)

    http://www.codewrecks.com/blog/index.php/2010/04/15/asp-net-and-an-hiddenfield-inside-a-disable-panel/

    Monday, January 30, 2012

    Getting Class Name and Method name using reflection

    To get the current method and class name in which the code is executing, we can use reflection.

    Method Details

    System.Reflection.MethodBase.GetCurrentMethod().Name, 
    
    
    Class Details
    System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name
    
    
    
    Handy to log the errors .. 

    Thursday, January 26, 2012

    Error :Attempted to access an unloaded appdomain

    Attempted to access an unloaded appdomain. (Exception from HRESULT: 0x80131014)

    This occurs when we try to open two different connections in the same  Transaction Scope . Use Transaction Scope.Suppress for one of the connection if you are not performing any transaction in one of the connection.


    But if you are making transactions in both of the connections as a single one ... i need to study further about this ... probably you have to open a new transaction under the main one .. will verify later 

    Dynamic Grouping in SSRS

    To achieve dynamic grouping in SSRS , i.e you group by a parameter chosen by the user.

    1) Send the group by parameter to the stored procedure/sql statement and let SQL handle the grouping by case statement
     Ex :
        SELECT   case(@groupby)
    when 'gender' then dummy.Gender
    when 'race' then dummy.Race
    when 'district' then dummy.District
    end "groupbyfield",
    count(*)"Count",
     FROM  dbo.dummy
    WHERE DummyDate BETWEEN @startdate and @enddate
         GROUP BYcase(@groupby)
    when 'gender' then dummy.Gender
    when 'race' then dummy.Race
    when 'district' then dummy.District
    end "groupbyfield"

    2) Sort by the "groupbyfield"  in SSRS.

    Wednesday, January 25, 2012

    Generating Enums from Database for Lookup Tables

    These are the two links i found for this problem.



    http://erraticdev.blogspot.com/2011/01/generate-enum-of-database-lookup-table.html


    http://idisposable.co.uk/2010/03/using-t4-to-generate-enums-from-database-lookup-tables/#viewSource





     I implemented the second one as i found it easier and more flexible in naming the enums differently from the database look-ups.I struggled with this for a few hours as i did not one thing . i.e When we add t4 template to VS make sure that it  in the properties of the t4 file the custom tool is set to "TextTemplatingFileGenerator". The default one is the text processing .. so i could not see the enum file .. Finally after some time i could identify this.




    This is really nice because you find your code more readable while not loosing flexibility of look-ups. Every time you have a new look-up you have to regenerate the t4 template and build your project.


    Thanks to people who wrote these templates :). It made my life easier.

    Thursday, January 12, 2012

    Required Field Validator for Dropdown


    Set the RequiredFieldValidator.InitialValue property to the value of your prompt item like so: 
    <asp:dropdownlist id="DropDownList1" runat="server" autopostback="True"         onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            <asp:listitem value="-1">Select Option</asp:listitem>
            <asp:listitem>A</asp:listitem>
            <asp:listitem>B</asp:listitem>
            <asp:listitem>C</asp:listitem>
    </asp:dropdownlist>
    <asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server"         errormessage="RequiredFieldValidator" controltovalidate="DropDownList1"         display="Dynamic" initialvalue="-1" setfocusonerror="True">
    </asp:requiredfieldvalidator>
    <asp:button id="Button1" runat="server" text="Button" />