VS 2017 RC

Wow now is Visual Studio 2017 available for test (release candidate version). Microsoft seems to release a new version every second year now of Visual Studio. Some new features I really like so far:

  • Visual Studio has been optimized to reduce startup time and solution load time. The very first launch of Visual Studio is at least 50% faster. I mean who likes slow software. =)
  • Reference method returns.
  • Value tuples where you could convert anonymous object to a tuple.

Get i from: https://www.visualstudio.com/vs/visual-studio-2017-rc/

 

Benchmarking – SQL with and without index

Everybody likes when processes are running at optimal performance. SQL queries is a typical example where the answer of the two equal queries can be delivered with different speed.
Indexes on a table can have a large impact on the performance of a SQL query. I’ve done some benchmark tests running the same query on a table with and without a index.

The table structure: TestIndex (rowId PK int, productId int not null, countryId int not null). The table contains of 100000 rows.

The SQL query:
set statistics time on;
select productId, count(productId) name, min(countryId)
from testindex T2
where productId > 29500000 and productId < 30000000 AND productId IN
(
select productId from testindex
group by productId having count(productId) < 2
)
AND
productId IN
(
select productId from testindex
group by productId having count(productId) < 3
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
AND
productId IN
(
select productId from testindex where countryId < 100
group by productId having count(productId) > 0
)
group by productid, name, countryId
order by productId desc
set statistics time off;

The index was created like this:
CREATE NONCLUSTERED INDEX testIndexOne
ON testindex (productId)

Benchmark results

CPU time no index CPU time with index Elapsed time no index Elapsed time with index
94 0 7006 60
15 0 6267 30
31 0 6000 61
47 0 6218 32
235 0 6276 31

As you can see in the benchmark results above there is a huge different in both CPU- and elapsed time for running the exactly the same query. The only difference was an added index on one of the columns in the table that was queried.

Unable to launch the IIS Express Web server

Failed to register URL “http://localhost:63647” for site application. Error description: The process cannot access the file because it is being used by another process (0x80070020).

1. Open project properties.
2. Choose “Web” on the left hand side.
3. Update the port number in the project URL. Then click yes if you want to update the virtual directory.
VisualStudio_Project URL

4. Save and restart Visual studio, then you should be good to go! =)

 

Section is locked (ipSecurity configuration)

Module IpRestrictionModule
Notification BeginRequest
Handler ExtensionlessUrl-Integrated-4.0
Error Code 0x80070021
Config Error This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault=”Deny”), or set explicitly by a location tag with overrideMode=”Deny” or the legacy allowOverride=”false”.

Update file: applicationhost.config (%userprofile%\documents\iisexpress\config\applicationhost.config)

Change line:
<section name=”ipSecurity” overrideModeDefault=”Deny” />

To:
<section name=”ipSecurity” overrideModeDefault=”Allow” />

And in web.config use:

<system.webServer>
<security>
<ipSecurity allowUnlisted=”false” denyAction=”Unauthorized”>
<clear/>
<add ipAddress=”X.X.X.X” allowed=”true” subnetMask=”255.255.255.0″ />
</ipSecurity>
</security>
</system.webServer>

Database entity model was generated with warnings or errors (asp.net)

Got some errors when trying to generate a DB entity model for a ASP.net MVC website. The error message was “The model was generated with warnings or errors. Please see the Error List for more details. These issues must be fixed before running your application”.

This turned to be caused by some tables that was lacking a primary key. Once a primary key was set on these tables the model could be generated successfully.

Convert float string to int c#

Converting a string to a integer seems to be trivial. But there could be endless of formats and styles on the string so it’s not always that easy that it’s seems.

If you have a string like “629.00” and want convert it to a int like 629. You can do like this:

int.Parse( ("629.00").Replace('.',','), NumberStyles.Float)

But if you try the code above with for example value “3187.50” instead you get this error message:

vid System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
vid System.Int32.Parse(String s, NumberStyles style)
vid System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
vid System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
vid Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
vid System.Threading.ThreadHelper.ThreadStart_Context(Object state)
vid System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
vid System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
vid System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

Then you need to do like:

(int) double.Parse("3187.50".Replace('.', ','), NumberStyles.Float)

View current sql queries on MSSQL database

To view current sql queries running on sql database you can use this sql script to get current query and elapsed time.

SELECT sqltext.TEXT,
req.session_id,
req.status,
req.command,
req.cpu_time,
req.total_elapsed_time
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext

I have only tested the script Microsoft SQL Server 2012 and therefore I’m not sure if it’s working on MySQL.

Abstract InjectionMemberElement object cannot be created

Case: Azure webapp. Solution with multiple projects that uses unity.

Working fine on localhost but not when published, getting the message:

An error occurred creating the configuration section handler for unity: An abstract InjectionMemberElement object cannot be created. Please specify a concrete type.”

Unity is defined in the web.config as:

<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
</configSections>
</configuration>

<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
...
</unity

Isolved it by renaming the unity tags to “unityX” so I suspect that the IIS already has loaded unity from another referenced project in the solution.

After the renaming it doesn’t work locally cause it then can’t find and load unity. But that’s another issue…

 

Entity type is not part of the model for current context

The entity type <Type> is not part of the model for the current context.

ExceptionType:
System.InvalidOperationException
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
vid System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
vid System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()
--- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---
vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
vid System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
vid System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()

Cause:
Wrong meta data in the MVC entity framework connection string. Had multiple entity models to seperate databases in the project. But had copied the connection strings to the other databases and changed the database settings and credentials. But forgot to update the entity model names in the meta data section of the connectionstring.

Solution:
Update database model names in the connection strings.