Friday, October 18, 2013

Cycle from file with specified extension and do something in script


FOR %variable IN (set) DO command [command-parameters]

Example: cycle through all assemblies in current directory and install them in GAC
for /f  %%a IN ('dir /b *.dll') do  gacutil -i  %%a

Monday, September 23, 2013

How to find when index was created?

SELECT STATS_DATE(OBJECT_ID([TablName]), (SELECT index_id FROM sys.indexes WHERE name = [Index Name]))

How to query SQL Profiler's trace file?

1. Read from the trace file into temp table in DB
2. Query table

SELECT * INTO MyTraceTemp

FROM ::fn_trace_gettable('c:\x\MyTrace.trc', default)

SELECT Reads, Duration, * FROM MyTraceTemp ORDER BY Reads DESC

How to find sp modified in last N dates

-- updated in last 6 days
SELECT name
FROM sys.objects
WHERE type = 'I'
AND DATEDIFF(D,modify_date, GETDATE()) < 7


-- created in last 6 days
SELECT name
FROM sys.objects
WHERE type = 'P'
AND DATEDIFF(D,create_date, GETDATE()) < 7

Wednesday, September 18, 2013

How to find most expensive query?

See http://blog.sqlauthority.com/2010/05/14/sql-server-find-most-expensive-queries-using-dmv/

from the link

SELECT TOP 10 SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1,
((CASE qs.statement_end_offset
WHEN -1 THEN DATALENGTH(qt.TEXT)
ELSE qs.statement_end_offset
END - qs.statement_start_offset)/2)+1),
qs.execution_count,
qs.total_logical_reads, qs.last_logical_reads,
qs.total_logical_writes, qs.last_logical_writes,
qs.total_worker_time,
qs.last_worker_time,
qs.total_elapsed_time/1000000 total_elapsed_time_in_S,
qs.last_elapsed_time/1000000 last_elapsed_time_in_S,
qs.last_execution_time,
qp.query_plan
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
ORDER BY qs.total_logical_reads DESC -- logical reads
-- ORDER BY qs.total_logical_writes DESC -- logical writes
-- ORDER BY qs.total_worker_time DESC -- CPU time

This seems to give stats for cached query. See discussion

Tuesday, June 11, 2013

Azure troubleshooting

1. Getting server error when running an app in Cloud after deploying to Azure.

    - create web site on Azure
    - create basic MVC 4 web application in VS2010 (.NET Framework 4.0) and deploy
    Symptom: 
    Not running in a hosted service or the Development Fabric.
  see details bellow
  Resolution:
  There seems to be a conflict with DiagnosticMonitorTraceListener component.
  Remove
<trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>

    see http://stackoverflow.com/questions/13879443/not-running-in-a-hosted-service-or-the-development-fabric-production-not-debug

Error details

Server Error in '/' Application.

Not running in a hosted service or the Development Fabric.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Not running in a hosted service or the Development Fabric.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: Not running in a hosted service or the Development Fabric.]
   Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.GetDefaultStartupInfoForCurrentRoleInstance() +357
   Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener..ctor() +40

[ConfigurationErrorsException: Could not create Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.]
   System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType, String initializeData) +6755589
   System.Diagnostics.TypedElement.BaseGetRuntimeObject() +45
   System.Diagnostics.ListenerElement.GetRuntimeObject() +83
   System.Diagnostics.ListenerElementsCollection.GetRuntimeObject() +143
   System.Diagnostics.TraceInternal.get_Listeners() +181
   System.Diagnostics.TraceInternal.TraceEvent(TraceEventType eventType, Int32 id, String format, Object[] args) +155
   DotNetOpenAuth.Loggers.TraceLogger.Info(Object message) +26
   DotNetOpenAuth.Logger.CreateWithBanner(String name) +45
   DotNetOpenAuth.Logger..cctor() +14

[TypeInitializationException: The type initializer for 'DotNetOpenAuth.Logger' threw an exception.]
   DotNetOpenAuth.Logger.get_Library() +14
   DotNetOpenAuth.Reporting.Initialize() +410
   DotNetOpenAuth.Reporting.set_Enabled(Boolean value) +31
   DotNetOpenAuth.Reporting..cctor() +285

[TypeInitializationException: The type initializer for 'DotNetOpenAuth.Reporting' threw an exception.]
   Microsoft.Web.WebPages.OAuth.PreApplicationStartCode.Start() +41

[InvalidOperationException: The pre-application start initialization method Start on type Microsoft.Web.WebPages.OAuth.PreApplicationStartCode threw an exception with the following error message: The type initializer for 'DotNetOpenAuth.Reporting' threw an exception..]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +550
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

[HttpException (0x80004005): The pre-application start initialization method Start on type Microsoft.Web.WebPages.OAuth.PreApplicationStartCode threw an exception with the following error message: The type initializer for 'DotNetOpenAuth.Reporting' threw an exception..]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873784
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254


      Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18033


Wednesday, March 6, 2013

Monday, March 4, 2013

Page authoring recipes

1. How to redirect from the page to a different page on client side
    document.location.href = 'url'
    - How to make a button to redirect to a different page when clicked using JQuery
         $('button selector').click(function{
            document.location.href = 'the-link-to-go';
         })
   


Monday, February 11, 2013

How to generate population script from existing data?

From SQL Management Studio
1. Select database
2. Right click and choose Task
3. Choose generate scripts
4. Choose objects
5. Select specific database objects
6. ... Go to advance. In General block choose 'Data Only' for type of data to script.

UnitTest code generation in VS2012

You can generate unit test by running command EditorContextMenus.CodeWindow.CreateUnitTests.
How
In option go to Keyboard left side menu. Search for the command. Put for instance unittest.  Add keyboard mapping to the above command. For instance assign it to the command Ctrl+Shift+?
Open you file and press you shortcut keys.




Friday, January 11, 2013

Tool list

1. StyleCop
StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project. StyleCop has also been integrated into many third-party development tools

2. Eqatec Profiler

From EQATEC:

The EQATEC Profiler is a code profiler, not a memory profiler. So it's all about making your app run faster, not about tracking objects and memory. The report will tell you exactly how many times each method was called and how long it took. You can then speedup your application by optimizing just the most expensive methods.

3. Mockup Builder
Free mockup software

From Mockup Builder
Mockup – it is the convenient software, which allows you to make a prototype of a site and new design for soft. We offer you to try possibilities of this program and to create web prototypes. Mockup has all necessary tools for giving the original look to appearance of websites. It is very convenient to use mockup for a web design. Numerous elements in UI promote development of ideas of modernization. You can download this program from our website or use its possibilities online. We can help with development of this program and we provide comprehensive support. Mockup has many functions. The program allows:
  • to draw a prototype of a site;
  • to create prototypes for mobile appendices for smart phones
  • to do breadboard models for desktop programs

Tuesday, January 8, 2013

Performance tools


MVC Mini Profiler (http://miniprofiler.com/) should be used to display performance results on the mvc views and can include Entity Framework calls. This can also be used in a production environment without performance issues but should be only viewable to administrators.

Also, the following tools can be used to check performance for web applications:
·         Google Chrome’s speed tracer
·         YSlow    
P    
      Load testing
      Grider
      Tutorial

P




Monday, January 7, 2013

Error logging tools

Elmah
     Overview extracted from the article
     As promised, here is my next article regarding another tool I find completely invaluable in my life as a developer,Elmah. Basically Elmah sites quietly on your site, logging any exceptions (Code based or Web Server, for example, 404) which occur to (in this example) a database.  It then provides a nice neat GUI front end to allow you to view the details of these errors, including stack traces. If you're anything like me, and are tired of conversations which go like this:
  • User: "Karl, the website crashed earlier"
  • Karl: "Oh right, what were you doing"
  • User: "I don't remember, I was just on it, can you fix it please"
  • Karl: "Well I could do with reproducing it...
You will be happy Elmah exists!