If you used a SQL login and needed to restore a database (dev/test), you should notice that your SQL login doesn’t work for the database anymore. The reason for this is that SQL login and database user mapping was lost. Even you can see the user name in database user’s mapping, however in internal SQL memory the restored database’s user has different reference than the SQL login.
Sometimes you need to find a specific string or value in a database that you are not familiar with. You may not know where to start since a completely new database for you, or there are just way too many tables. In such cases there is a very handy stored procedure that searches for a string through all the tables.Continue reading SearchAllTables SQL Stored Procedure
The best practice to run SQL queries is to run them in transaction and wrap with SQL’s Try … Catch statement, so we could rollback the transaction, and throw an exception. Below is the code snippet that would do it all.Continue reading Try … Catch in SQL
Just a quick reminder on how to set up TestCaseSource with NUnit. It can save a few lines of code when you want to test the same method using different sets of values. We will use TDD approach to implement our sample method and unit test it.Continue reading NUnit TestCaseSource example (advanced)
In my previous blog post I’ve implemented a very simple application to illustrate dependency injection (DI) using Ninject. While Ninject is flexible and powerful, you might want to try different dependency injection libraries before you make your final decision on what to use. And this time I wanted to look into the latest dependency injection library which comes as a default option for MVC 6 and .NET Core – Microsoft Dependency Injection. And yes, the name is very easy to remember :)Continue reading Microsoft Dependency Injection and MVC6
It has been a while since my last blog post, and I decided to continue series of simple examples of dependency injection (DI). Last time I had an example of not so well known but extremely simple and fast Simple Injector. This time I wanted to replace the Simple Injector with a more popular Ninject, and see if there are any big differences in terms of set up. I chose Ninject mostly just because of the Japan-related name:)Continue reading Ninject and ASP.NET MVC 5
A very quick tip how to solve “HTTP Error 403.16 – Forbidden” issue when trying to run a new MVC web application on Windows 10 using IIS 10 Express. After some quick tests and research on Google I made a conclusion that this problem is actually not related neither to Windows, nor IIS.Continue reading HTTP Error 403.16 – Forbidden – IIS 10 Express
One more useful SQL code snippet – sp_generate_inserts. This stored procedure (SP) generates SQL insert statements of existing data from the table specified. It is a very handy script when you have limited options to make a database backup file, but still need to export data.
This script was originally written by Narayana Vyas Kondreddi back in 2002, however his website is not accessible any more. Therefore I had to slightly modify the script to work on Azure SQL databases, since Azure SQL has some limitations/changes compared to classical MSSQL.Continue reading sp_generate_inserts Azure SQL
MSSQL server index fragmentation check code snippet I had in my archive. It shows what indices would be good to add, and also shows the most CPU intense queries. A nice SQL optimization toolkit.Continue reading Index fragmentation in MSSQL Server
Using ASP .NET MVC 5 still has the classical web application project structure (compared against the new MVC 6), and dependency injection (DI) is quite straightforward using a third party library. And to make this process even simpler, I decided to try out Simple Injector. It’s a very simple and fast DI .NET library.Continue reading Simple Injector and ASP.NET MVC 5