Thursday, September 22, 2016

.Net temp folder location on development box

Problem:



I was trying to locate the asp.net temp during a local build session.  I know that the CLR compiles and binds its code in the c:\windows\microsoft.net\framework\... temp area.  But during a local session on a dev box it is built somewhere else.


Solution:



It is in c:\Users\UserName\AppData\Local\Temp\Temporary ASP.NET Files\root\



Thursday, September 15, 2016

Cannot resolve the collation conflict between "Latin1_General_BIN" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.

Problem:
I was trying to migrate data from one catalog to the other and hit this error. 


insert claim

select

*

from [MANNHEIM].dbo.CLAIM c

Inner Join Exercise e

on e.Exercise_ID = c.EXERCISE_ID

where e.EXERCISE_ID is not null


The problem was that the field in the source table had a different default format then
the target field.  The way around was to force the query to use a common default collation.




Solution:


insert claim
select
from [MANNHEIM].dbo.CLAIM c
Inner Join Exercise e
on e.Exercise_ID COLLATE DATABASE_DEFAULT = c.EXERCISE_ID COLLATE DATABASE_DEFAULT
where e.EXERCISE_ID is not null


Source:
http://blog.sqlauthority.com/2007/06/11/sql-server-cannot-resolve-collation-conflict-for-equal-to-operation/

Friday, September 9, 2016

SQL Server count rows in a database

Problem:

I began analyzing a legacy database and need to get some statistics on what is being used.
I needed to get a feel for which tables were actually being used.

Solution:

select
schema_name(obj.schema_id) + '.' + obj.name AS [TableName],
row_count
from (
    select
        object_id,
        row_count = sum(row_count)
    from sys.dm_db_partition_stats
    where index_id < 2  -- heap or clustered index
    group by object_id
) Q
join sys.tables obj on obj.object_id = Q.object_id
where row_count > 0
order by [TableName]


Source:

http://stackoverflow.com/questions/428458/counting-rows-for-all-tables-at-once

Wednesday, August 31, 2016

MVC multiple layouts

Issue:

Working an MVC project which required us to use different layouts.  I knew you could do it but was not sure of the syntax. 

Solution:

It turns out there are at least 4 ways to do this.  I only am mentioning the solution we used since it is what we needed.  Feel free to the Net Stuff blog for more details.

Set Layout by Returning from ActionResult

You can override the default layout rendering by returning the layout from the ActionResult. So, this is also a way to render different Layout in your ASP.NET MVC application.




public ActionResult Index()
{
 SampleModel model = new SampleModel();
 //Any Logic
 return View("Index", "_WebmasterLayout", model);
}


Source:

http://www.dotnet-stuff.com/tutorials/aspnet-mvc/how-to-render-different-layout-in-asp-net-mvc

Wednesday, July 20, 2016

0x800a1391 - JavaScript runtime error: '$' is undefined

Problem:

I had decided to upgrade to a newer version of bootstrap datepicker.  I had a new MVC project which started giving me this strange jquery error.


Solution:

The problem I ran into when getting this error was due to the fact that the following statements were not in the <head> of the document, but just before the </body> tag at the end of the document.
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/bootstrap")
Once I moved them to the <head> of my .cshtml file, everything worked fine.


Source:

http://stackoverflow.com/questions/17672643/0x800a1391-javascript-runtime-error-jquery-is-undefined-mvc-4

Tuesday, July 19, 2016

Customize .Net compilation directory.

Problem:

I had a vs project today which was building over another project.  The IIS express was referencing the older project each time I tried to run the new project.  What I needed to do was wipe the temp files.


Solution:

The dynamic created files for your web site are stored on

c:\WINDOWS\Microsoft.NET\Framework\version\Temporary ASP.NET Files\

You can change this directory on the web.config. The asp.net check if any file change on your site and if can find any changes is start the recompile. Also many parameters of the recompile can change on web.config.



<compilation  tempDirectory="" ...>






Source:

  1. http://stackoverflow.com/questions/12018403/where-is-the-compiled-dll-for-a-website-project
  2. https://msdn.microsoft.com/en-us/library/s10awwz0%28VS.100%29.aspx?f=255&MSPPError=-2147217396

Thursday, July 14, 2016

Keyset does not exist

Problem:

I have some code that makes a call to an external web service that is secured using X.509 certification.  If I call the service using the application pool set to Local service then it executes.


When I set the app pool to use a domain account domain\svc.account the webservice fails with the error: Keyset does not exist.


Solution:

This certificate is installed correctly but the domain account needs to be granted permissions to that certificate.  This will allow the service account to access the private key attached to the certificate.


  1. Start -> Run -> MMC
  2. File -> Add/Remove Snapin
  3. Add the Certificates Snap In
  4. Select Computer Account, then hit next
  5. Select Local Computer (the default), then click Finish
  6. On the left panel from Console Root, navigate to Certificates (Local Computer) -> Personal -> Certificates
  7. Your certificate will most likely be here.
  8. Right click on your certificate -> All Tasks -> Manage Private Keys



       9.Add you service account to the access list.  It will need a minimum of read permissions.




      10.It is possible that you may be required to add the local IIS_USRS group to the access list.  Grant it read permissions.

Source