European Windows 2012 Hosting BLOG

BLOG about Windows 2012 Hosting and SQL 2012 Hosting - Dedicated to European Windows Hosting Customer

ASP.NET 5 Hosting - HostForLIFE.eu :: ASP.NET 5 Dependency Injection

clock April 8, 2016 00:40 by author Anthony

Dependency Injection occurs when a software component (in this case, the class) given their dependencies through their constructors, methods, or directly into the fields. Simply put, Dependency Injection is passing or setting of dependencies into a software component (Dependency Injection Container). In other words, if a class can not do his job without a dependency, then there was a dependency injection. Classes are diinject, not only can build the object, but also its behavior.

Dependency injection can be done through three ways :

  • Constructor Injection
  • Setter Injection
  • Interface Injection

ASP.NET 5 has dependcy injection available at framework level and ASP.NET 5 makes heavy use of it. Most of things surrounding controllers, views and other MVC components are implemented as services that web applications consume. This post is quick overview of dependency injection in ASP.NET 5 with some examples.

Registering services

Services are registered when application starts. It happens in Startup class. There is method called ConfigureServices() and in the end of this method I usually define service mappings.

public virtual void ConfigureServices(IServiceCollection services)
{
    // configure services
 
    var settings = new Settings();
 
    // initialize custom settings
 
    services.AddInstance(settings);
    services.AddScoped<IFileClient, AzureFileClient>();
    services.AddScoped<IMapperSession, MapperSession>();
    services.AddScoped<IProductService, ProductService>();
}

Available scopes for services are:

  • Singleton – always return same instance.
  • Transient – return new instance every time.
  • Scoped – return same instance in current scope (it’s like singleton in current scope – think about requst scope by example).
  • Instance – specific instance is returned every time and it’s up to you how it is actually ceated.
  • Services registered during application start-up are available to all classes invoked through dependency injection.


Although we can inject services to whatever classes you need there are some things made very convenient for us. Let’s see now how injection works with controllers and views.

Injecting services to controller

We don’t need custom controller factories anymore if we don’t use some other dependency injection container. Also we don’t have to dig around in system variables and classes to find settings we need. We can do it all through dependency injection. Here is the example how to provide environment information and some custom services to controller.

public class HomeController : Controller
{
    private readonly IApplicationEnvironment _appEnvironment;
    private readonly ShopContext _shopContext;
    private readonly IProductService _productService;
 
    public HomeController(ShopContext shopContext,
                          IProductService productService,
                          IApplicationEnvironment appEnvironment)
    {
        _appEnvironment = appEnvironment;
        _shopContext = shopContext;
        _productService = productService;
    }
 
    public IActionResult Index()
    {
        return View();
    }

The code here uses controller injection – the only injecton mode supported by ASP.NET right now. We don’t have to do anything special for dependency injection to happen. We just make sure we register our custom services at application startup.

 

Injecting services to views

It’s also possible now to inject services to views. There’s new syntax for this.

@model ProductCategoryMenuModel
@inject ShopContext ShopContext

<h1>@ShopContext.PageTitle</h1>
 
<ul>
    <!-- write out categories here -->
</ul>

tells to view engine that we want instance of ShopContext to be injected to view and we name it as ShopContext. Perhaps it’s not a good practice to name variable as type in view but still it communicates the purpose of variable well.

Conclusion

Framework level dependency injection in ASP.NET 5 is very transparent and configuration is simple. First register type mappings in application start-up and then we use constructor injection to get instances to our classes. This way we can use classes by interfaces and we don’t have to create instances in our own code. On MVC side we can use dependency injection for controller, views and view components.

 

HostForLIFE.eu ASP.NET 5 Hosting
HostForLIFE.eu revolutionized hosting with Plesk Control Panel, a Web-based interface that provides customers with 24x7 access to their server and site configuration tools. Plesk completes requests in seconds. It is included free with each hosting account. Renowned for its comprehensive functionality - beyond other hosting control panels - and ease of use, Plesk Control Panel is available only to HostForLIFE's customers. They
offer a highly redundant, carrier-class architecture, designed around the needs of shared hosting customers.



SQL Server 2014 Hosting - HostForLIFE.eu :: How to Optimize Tempdb Performance?

clock April 6, 2016 20:14 by author Anthony

In this tutorial, I will explain optimize tempdb performance. Tempdb is re-created every time SQL Server is started so that the system always starts with a clean copy of the database. Temporary tables and stored procedures are dropped automatically on disconnect, and no connections are active when the system is shut down.

But before we start, there are things you should know :

  • If your SQL Server instance doesn’t employ many of the activities just described, then tempdb performance may not be an issue for you.
  • On the other hand, if your SQL Server instance uses many of these features, then tempdb could become a significant bottleneck for your SQL Server instance.
  • Only by investigation will you know.
  • Keep in mind that there is only one tempdb, and it is possible for one misbehaved application and database to indirectly affect the performance of all the other databaseson the same instance.

Tempdb Internals

  • Tempdb is dropped and recreated every time the SQL Server service is stopped and restarted.
  • When SQL Server is restarted, tempdb inherits many of the characteristics of model, and creates an MDF file of 8MB and an LDF file of 1MB.
  • Autogrowth is set to grow by 10% with unrestricted growth.
  • Each SQL Server instance may have only one tempdb, although tempdb may have multiple physical files.
  • Tempdb often doesn’t act like other databases
  • Tempdb only uses the simple recovery model.
  • Many database options can’t be changed (e.g. Database Read-Only, Auto Close, Auto Shrink).
  • Tempdb may not be dropped, detached, or attached.
  • Tempdb may not be backed up, restored, be mirrored, have database snapshots made of it, or have many DBCC commands run against it.
  • Tempdb logging works differently from regular logging. Operations are only minimally logged with enough information to roll back transactions, but not to be rolled forward. The log is truncated constantly, although it can grow with long-running transactions.

Execution Plans and tempdb

  • When a query execution plan is cached, the tempdb work tables required by the plan, if any, are often cached.
  • When a work table is cached, the table is truncated (from the previous execution of the code) and up to nine pages remain in the cache for reuse.
  • This improves the performance of the next execution of the query.
  • If the system is low on memory, the Database Engine removes the execution plan and drops the associated work tables.

Types of tempdb Problems

Generally, there are three major problems you run into with tempdb:

  • Tempdb is experiencing an I/O bottleneck, hurting server performance.
  • Tempdb is experiencing DDL and/or allocation contention on various global allocation structures (metadata pages) as temporary objects are being created, populated, and dropped. E.G. Any space-changing operation (such as INSERT) acquires a latch on PFS, SGAM or GAM pages to update space allocation metadata. A large number of such operations can cause excessive waits while latches are acquired, creating a bottleneck, and hurting performance.
  • Tempdb has run out of space.

Ideally, you should be monitoring all these on a proactive basis.

Identifying tempdb I/O Problems

  • Use Performance Monitor to determine how busy the disk is where your tempdb MDF and LDF files are located.
  • LogicalDisk Object: Avg. Disk Sec/Read: The average time, in seconds, of a read of data from disk. Numbers below are a general guide only and may not apply to your hardware configuration.
  • Less than 10 milliseconds (ms) = very good
  • Between 10-20 ms = okay
  • Between 20-50 ms = slow, needs attention
  • Greater than 50 ms = serious IO bottleneck
  • LogicalDisk Object: Avg. Disk Sec/Write: The average time, in seconds, of a write of data to the disk. See above guidelines.
  • LogicalDisk: %Disk Time: The percentage of elapsed time that the selected disk drive is busy servicing read or write requests. A general guideline is that if this value > 50%, there is an I/O bottleneck.
  • SQL Server Database: Log Bytes Flushed/sec: The total number of log bytes flushed. A large value indicates heavy log activity in tempdb.
  • SQL Server Database: Log Flush Waits/sec: The number of commits that are waiting on log flush. Although transactions do not wait for the log to be flushed in tempdb, a high number in this performance counter indicates an I/O bottleneck on the disk associated with the log.

Identifying Contention on Allocation Structures

Use these performance counters to monitor allocation/deallocation contention in SQL Server:

  • Access Methods:Worktables Created/sec: The number of work tables created per second. Work tables are temporary objects and are used to store results for query spool, LOB variables, and cursors. This number should generally be less than 200, but can vary based on your hardware.
  • Access Methods:Workfiles Created/sec: The number of work files created per second. Work files are similar to work tables but are created by hashing operations. Work files are used to store temporary results for hash joins and hash aggregates.
  • Temp Tables Creation Rate: The number of temporary tables or variables created/sec.
  • Temp Tables For Destruction: The number of temporary tables or variables waiting to be destroyed by the cleanup system thread.

Add More RAM to Your Server

  • Depending on the operation, SQL Server tries to perform the action in the buffer cache. (e.g. sorts, CTEs)
  • If the buffer cache does not have enough available space, then the operation may have to spill to tempdb.
  • This places additional overhead on tempdb.
  • If your server is experiencing a memory bottleneck, then adding RAM can help reduce the load on tempdb.
  • On the other hand, if your server has plenty of memory, adding more won’t help tempdb performance.

How to Pre-allocate tempdb Space

Use ALTER DATABASE, or SSMS, to increase the size of the tempdb database MDF and LDF files.

    USE master;
    GO
    ALTER DATABASE tempdb
    MODIFY FILE
    (NAME = tempdev,
    SIZE = 20MB);
    GO
    ALTER DATABASE tempdb MODIFY FILE
    (NAME = templog, SIZE = 10MB)
    GO

Locate tempdb on Fast I/O Subsystem

  • Always locate tempdb on the fastest I/O subsystem you have available.
  • Prefer RAID 1 or RAID 10. RAID 5 is slow for writes and should generally be avoided for tempdb, as tempdb is often write-intensive.
  • If using a SAN, consult with a SAN engineer to ensure that tempdb won’t be affected by other disk I/O.
  • Consider SSD drives for tempdb MDF and LDF files.

How to Move tempdb

  • Determine the current location of the MDF and LDF files
  • Run the ALTER DATABASE command to move the files

Avoid Using TDE

  • SQL Server 2008 offers a new database-level encryption feature called Transparent Database Encryption (TDE).
  • If this is turned on for one or more databases on a SQL Server instance, then all the activity in tempdb (whether it comes from a encrypted or non-encrypted database) will be encrypted.
  • Encryption increases CPU usage and slows down tempdb performance.
  • If you decide to use TDE, you will want to incorporate as many of the tempdb performance tuning tips that I have suggested in order to help overcome the additional burden added by TDE.


HostForLIFE.eu SQL Server 2014 Hosting
HostForLIFE.eu revolutionized hosting with Plesk Control Panel, a Web-based interface that provides customers with 24x7 access to their server and site configuration tools. Plesk completes requests in seconds. It is included free with each hosting account. Renowned for its comprehensive functionality - beyond other hosting control panels - and ease of use, Plesk Control Panel is available only to HostForLIFE's customers. They
offer a highly redundant, carrier-class architecture, designed around the needs of shared hosting customers.



SQL Server 2014 Hosting - HostForLIFE.eu :: SQL 2014 Upgrade Tips

clock April 5, 2016 18:34 by author Anthony

SQL Server Migration is a mixing process prior to SQL Server implementation newer version to a different location due to strategic decisions (such as SQL Server Consolidation). So in this article, I will explain about things to check before planning to migrate your SQL Server, from SQL Server 2008 to SQL Server 2014.

Before migrating your sql server, there are several things you need to know :

  • Your Operating System must be at least 2008. Because SQL 2014 cannot be installed on Windows 2003.
  • Your platform must be the same. It cannot go from 32 to 64 or 64 to 32.
  • The edition cannot downgrade.
  • Remember, you can only migrate from 2008.

Please note that these steps are specific for an upgrade to the database schema and data. They do not include anything regarding the upgrading or testing of an application that is going to be accessing the upgraded database. You will want to remember to test your application and not just assume it will work perfectly even after the database has been upgraded. I would also advise that you perform these steps in a non-production environment first because I often find that common sense isn’t so common after all.

  • EXECUTING DBCC

Your upgrade tasks should be to run the following statement:

DBCC CHECKDB WITH DATA_PURITY;

This will check your data for values that are no longer valid for the column datatype. For databases created prior to SQL 2005, this step is rather important to take. For databases created in SQL 2005 and later, the DATA_PURITY check is supposed to be done automatically with a regular CHECKDB.

  • EXECUTING DBCC UPDATEUSAGE COMMAND

This one has a place in any migration or upgrade process:

DBCC UPDATEUSAGE(db_name);

This command will help to fix any page count inaccuracies that are resulting in the sp_spaceused stored procedure returning wrong results. For SQL Server 2012, this check was recommended for databases created prior to SQL Server 2005. However, in SQL Server 2014, the BOL entry link lists this command as being applicable for databases created in SQL Server 2008 and later. That seems odd to me, since this command is valid for SQL Server 2005.

  • UPDATING STATISTIC

This one is a MUST for any migration or upgrade checklist:

USE db_name;
GO
EXEC sp_updatestats;

This command will update the statistics for all the tables in your database. It issues the UPDATE STATISTICS command, which warrants mentioning because you may want to use that command with the FULLSCAN option. Don’t forget to update the statistics after an upgrade. Failure to do so could result in your queries running slowly as you start your testing and may end up wasting your time while you try to troubleshoot the possible bottlenecks. With SQL Server 2014 there is also a new Cardinality Estimator (CE).

  • REFRESHING YOUR VIEWS USING SP_REFRESHVIEW

Someone will build a view that spans into another database on the same instance. And, in what may be a complete surprise to many, sometimes these views will go across a linked server as well. The point here is that your view may not be of data that is contained in just the database on that single instance. In what could be the most dramatic twist of all, sometimes these views are created using a SELECT * syntax.

When you have bad code on top of views that go to other databases, you are going to want to use sp_refreshview to refresh those views. So, if you are migrating a database in your environment to a new server then it would be a good idea to refresh your views using sp_refreshview. Most of the time it won’t do anything for you, just like a burger topped with veggie bacon. But there is that one chance where it will dramatically improve performance and your customer will be happy as a result. Using sp_refreshview is a lot like flossing: it doesn’t take much effort, and the end result is usually worth it.

  • TAKING BACKUPS

You should have taken one prior to the start of any upgrade or migration, and you had better take one right before you turn that database over to your end users. Also, you should save any output from the items listed here, as it could prove helpful should something go awry later.

  • UPGRADING YOUR HARDWARE

Microsoft lists the minimum requirements for installing SQL Server 2014. However, chances are if your servers don’t already meet those requirements then you aren’t looking to upgrade anytime soon. But if you are upgrading, then it might be time to upgrade your hardware as well. You may even consider going virtual (if you aren’t already), which will still require you to examine your hardware requirements.

  • KNOWING THE RIGHT UPGRADE PATH

If you are running SQL Server 2000 instances. You are not able to upgrade directly to SQL Server 2014 without first upgrading to an intermediary version. You have two options to choose from when going from pre-SQL Server 2005 versions. The first option is to do an upgrade in place to SQL Server 2005, SQL Server 2008, or SQL Server 2008 R2. The second option is to do a backup (or even detach) your database and restore/attach to an instance running SQL Server 2005, SQL Server 2008, or SQL Server 2008 R2. At that point you will be able to complete the upgrade to SQL 2014.

  • CHECK YOUR COMPATIBILITY LEVELS

If you have been going through SQL Server upgrades for the past ten years then you are likely to have noticed that the compatibility level does not get set to the newest version after the migration is complete. You need to manually set the compatibility level yourself. With SQL Server 2014 this becomes more important than in previous versions due to the new Cardinality Estimator (CE).

  • READ THE RELEASE NOTES

Take a few minutes and read the release notes. They can be useful for you to review. It’s good to have as complete a picture as possible for the new version should something not work as expected, and there are details in the release notes you may not find elsewhere.

HostForLIFE.eu SQL 2014 Hosting
HostForLIFE.eu revolutionized hosting with Plesk Control Panel, a Web-based interface that provides customers with 24x7 access to their server and site configuration tools. Plesk completes requests in seconds. It is included free with each hosting account. Renowned for its comprehensive functionality - beyond other hosting control panels - and ease of use, Plesk Control Panel is available only to HostForLIFE's customers. They
offer a highly redundant, carrier-class architecture, designed around the needs of shared hosting customers.



SQL Server Hosting - HostForLIFE.eu :: Can Not Connect to Server on SQL Server

clock April 4, 2016 19:00 by author Anthony

Microsoft SQL Server is a relational database management system (RDBMS) products Microsoft. Primary query language is Transact-SQL is an implementation of SQL ANSI / ISO used by Microsoft and Sybase. SQL Server is generally used in the business world that has a data base of small to medium scale, but then developed with the use of SQL Server on large data bases.


Microsoft SQL Server and Sybase / ASE can communicate over the network by using a protocol TDS (Tabular Data Stream). Apart from that, Microsoft SQL Server also supports ODBC (Open Database Connectivity), and has a JDBC driver to the Java programming language. The other feature of SQL Server is the ability to create a database mirroring and clustering. In previous versions, MS SQL Server 2000 affected by the SQL Slammer computer worm which caused delays in access to the Internet on January 25, 2003.

SQL Server is the best solution of SQL that provides the capability for mission critical confidence, self-service Business Intelligence and can run on hybrid scenarios using cloud technology. SQL Server 2012 was launched with the simplification editions and licensing schemes. SQL Server is generally used in the business world that has a data base of small to medium scale, but what if at the time wanted to make turns SQL Server database can not connet to the server on the computer.

Cannot connect to XXXXXXX\SQLEXPRESS.

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (.Net SqlClient Data Provider).

  • Go to the "SQL Server Configuration Manager".
  • Then select the SQL Server Configuration Manager (local).
  • Then click SQL Server Services, the right side will appear.
  • Then right-click SQL Server (SQLEXPRESS) >> START. Then wait for the configuration is complete.
  • Restart Server SQL Server Management Studio.

HostForLIFE.eu SQL Hosting
HostForLIFE.eu revolutionized hosting with Plesk Control Panel, a Web-based interface that provides customers with 24x7 access to their server and site configuration tools. Plesk completes requests in seconds. It is included free with each hosting account. Renowned for its comprehensive functionality - beyond other hosting control panels - and ease of use, Plesk Control Panel is available only to HostForLIFE's customers. They
offer a highly redundant, carrier-class architecture, designed around the needs of shared hosting customers.



SQL Server 2014 Hosting - HostForLIFE.eu :: How to Install SQL Server 2014 on Windows 10?

clock March 31, 2016 19:16 by author Anthony

Windows 10 is an operating system developed by Microsoft. Microsoft user interface 10 is designed specifically to optimize the experience based on the type of device and provided input, provide the right experience on devices teoat and at the right time. Therefore, in this article I will discuss and explain how to install SQL Server 2014 on Windows 10 operating systems.

There are several ways that can be used to install SQL Server 2014. Through the command prompt, server core, and others. But in this discussion, I will explain the easiest way, which is through SQL Server 2014 Setup wizard.

  • The first thing to do is you need to download SQL Server 2014 from Microsoft. You are free to choose for x64 or x86 according to your operating system.
  • Then double click on the .exe file has been downloaded, or to extract it. Then click the setup.exe file from folder.
  • After that it will open the SQL Server Installation Center. Select Installation, then select New SQL Server stand-alone installation or add features to an existing installation
  • After that, please check the I accept the license terms and click Next.
  • Then let SQL Server 2014 installed.
  • image

  • Then it will appear in the SQL Server 2014 Setup, Feature Selection. Select the checkboxes as shown below and click the Next button.
  • image

  • Next will appear on the SQL Server 2014 Setup, Configuration Instance. You can fill in the Name Instance in accordance with the needs and desires. In this tutorial I will be using SQLExpress. Once completed, please click the Next button.
  • image

  • Then you will see Server Configuration. selective startup type for SQL Browser as Automatic. Note that this is optional and click the Next button.
  • Then on the Database Engine Configuration, the Server Configuration tab, please select Mixed Mode (SQL Server authentication and Windows authentication). Then enter the password as well. You can also add users by clicking Add Current User. Then select Next.
  • image

  • After that you will see the installation of SQL Server 2014 when the installation has been completed.
  • Then you can click on the Start menu windows, you will find SQL Server 2014 has been installed. Please click on the SQL Server 2014 Management Studio. Then enter the server name matches the name that you created. In this tutorial I will put SQLEXPRESS on the server name. After that please click the Connect button.
  •  

HostForLIFE.eu SQL 2014 Hosting
HostForLIFE.eu revolutionized hosting with Plesk Control Panel, a Web-based interface that provides customers with 24x7 access to their server and site configuration tools. Plesk completes requests in seconds. It is included free with each hosting account. Renowned for its comprehensive functionality - beyond other hosting control panels - and ease of use, Plesk Control Panel is available only to HostForLIFE's customers. They
offer a highly redundant, carrier-class architecture, designed around the needs of shared hosting customers.



SQL Server Hosting - HostForLIFE.eu :: How to Use Visual Studio 2010 as a SQL Server?

clock March 29, 2016 23:29 by author Anthony

In this article I will discuss about how to use Visual Studio 2010 as a SQL Server database management studio. If you want to create applications using the .NET Framework you certainly will need Microsoft Visual Studio as IDE to build your application. If you have installed SQL Server course you will need a SQL Server Management Studio as your medium to process and manipulate data.


What if you've already installed Microsoft Visual Studio but when installing Microsoft SQL Server does not install the SQL Server Management Studio?

Of course you can not query your data right, and you can only pass the command prompt. But with Microsoft Visual SQL Management Studio as the media, you can process the data in the Microsoft Visual Studio IDE

  1. Run Microsoft Visual Studio, and then open Server Explorer listed on the menu view. After that will appear Data Connection and Server.
  1. Add a data connection by clicking the right mouse button and select Add Connection. Then see the database connection will appear.
  2. Enter your name server as the instance name on your SQL Server, log into SQL by using the username and password to get access, or by using Windows authentication. Then select the database you want to use and then press the Test Connection button, and make sure that the connection to the database successfully.

  3. If the Data Connection has been filled with database structure view you have, and then query the data from the database table and by right-clicking on the Data Connection that you created and select New Query.

  4. It will display the Query Window. Then select the table you want to create the query. But not only the table that can be in the query, Views, Function and Synonims you can also query the right to suit your needs.

  5. Once you select a table, the query functioned in accordance with the display data or you can write a query that you want on the bottom. To be able to execute the query, you can click the Execute button or by pressing the F5 key

HostForLIFE.eu SQL Server Hosting

European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in