European Windows 2019 Hosting BLOG

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

SQL Server 2014 Hosting Belgium - HostForLIFE.eu :: Backup Verification Script on SQL Server

clock January 22, 2015 05:22 by author Peter

In this post, I will explain you about a script to verification on SQL Server 2014. There are situations wherever you have got to verify the multiple SQL Server instances backup within limited timeframe whether or not it meet your organization backup criteria standards or not.

You can execute below T-SQL script to see the backup status as per your organization normal by assignment backup conditions value to backup criteria variable. You'll execute below script either by connecting every SQL Server Instance or execute it by registering all the SQL Server Instances in Central Management Server (CMS).

Below T-SQL Script work with all the versions of MSSQL Server and verify FULL, Differential and transaction Log Backup. It'll check the max backup date and appraise result based on condition as backup is Passed or Not.

And this is the Backup Verification Script and it will return below values:

  • SQLInstanceName
  • DatabaseName
  • db_create_ddate
  • DB_Recovery_Model
  • dbstatus
  • windowsservername
  • productversion
  • productlevel
  • edition
  • current_datetime
  • last_full_backup_date
  • last_diff_backup_date
  • last_tran_backup_date
  • days_since_last_full_backup
  • days_since_last_diff_backup
  • hours_since_last_tranlog_backup
  • Full_Backup_Stauts
  • Diff_Backup_Stauts
  • Log_Backup_Stauts
  • full_backup_location
  • diff_backup_location
  • tlog_backup_location

You have to specify the backup condition based on your organization standard by assigning values to below variables.
declare @full_backup_criteria_in_days int
declare @diff_backup_criteria_in_days int
declare @log_backup_criteria_in_hours int
 -- specify the backup criteria
set @full_backup_criteria_in_days = 7 -- 7 day older Full Backup is Pass
set @diff_backup_criteria_in_days = 1 -- 1 day older Diff Backup is Pass
set @log_backup_criteria_in_hours = 2 -- 2 hours older Log Backup is Pass

This is the complete script that I used:
declare @full_backup_criteria_in_days int
declare @diff_backup_criteria_in_days int
declare @log_backup_criteria_in_hours int
-- specify the backup criteria
set @full_backup_criteria_in_days = 7 -- 7 day older Full Backup is Pass
set @diff_backup_criteria_in_days = 1 -- 1 day older Diff Backup is Pass
set @log_backup_criteria_in_hours = 2 -- 2 hours older Log Backup is Pass
select   
           serverproperty('servername') as SQLInstanceName,
           quotename(bkup_full.[database_name]) as DatabaseName,
            ( select    sdb.crdate
              from      [master]..[sysdatabases] sdb
              where     sdb.name = bkup_full.[database_name]
            ) as [db_create_ddate],         
           databasepropertyex(bkup_full.[database_name],'recovery')  as DB_Recovery_Model,
           databasepropertyex(bkup_full.[database_name],'status')  as dbstatus,     
           case serverproperty('isclustered')
                        when 1 then cast(serverproperty('computernamephysicalnetbios') as varchar)
                        when 0 then cast(serverproperty('machinename') as varchar)
           end as windowsservername,
           serverproperty('productversion') as productversion,
           serverproperty('productlevel') as productlevel,
           serverproperty('edition') as edition,
            current_timestamp as current_datetime,           
           bkup_full.[backup_finish_date] as [last_full_backup_date],         
           bkup_diff.[backup_finish_date] as [last_diff_backup_date] ,
           bkup_log.[backup_finish_date] as [last_tran_backup_date] ,
           datediff(dd, bkup_full.[backup_finish_date], current_timestamp) as [days_since_last_full_backup] ,
           datediff(dd, bkup_diff.[backup_finish_date], current_timestamp) as [days_since_last_diff_backup] ,
           datediff(hh, bkup_log.[backup_finish_date], current_timestamp) as [hours_since_last_tranlog_backup] ,            
           case
                        when datediff(dd, bkup_full.[backup_finish_date], current_timestamp) <= @full_backup_criteria_in_days
                        then 'Pass'
                        else 'Fail'
                        end as Full_Backup_Stauts,            
            case
                        when datediff(dd, bkup_diff.[backup_finish_date], current_timestamp) <= @diff_backup_criteria_in_days  then 'Pass'
                        else case when quotename(bkup_full.[database_name]) IN ('[master]') then 'N/A' else 'Fail' end                      
                        end as Diff_Backup_Stauts,
            case
                        when datediff(hh, bkup_log.[backup_finish_date], current_timestamp) <= @log_backup_criteria_in_hours  then 'Pass'
                        else case when databasepropertyex(bkup_full.[database_name],'recovery') = 'SIMPLE' then 'N/A' else 'Fail' end                      
            end as Log_Backup_Stauts,          
             ( select top 1 [physical_device_name]
              from      [msdb]..[backupmediafamily] bkup_media_family
              where     bkup_media_family.[media_set_id] = bkup_full.[media_set_id]
            ) as [full_backup_location] ,
            ( select top 1  [physical_device_name]
              from      [msdb]..[backupmediafamily] bkup_media_family
              where     bkup_media_family.[media_set_id] = bkup_diff.[media_set_id]
            ) as [diff_backup_location] ,
            ( select top 1  [physical_device_name]
              from      [msdb]..[backupmediafamily] bkup_media_family
              where     bkup_media_family.[media_set_id] = bkup_log.[media_set_id]
            ) as [tlog_backup_location]                                       
    from    [msdb]..[backupset] as bkup_full
            left join [msdb]..[backupset] as bkup_log on bkup_log.[database_name] = bkup_full.[database_name]
               and bkup_log.[server_name] = bkup_full.[server_name]
               and bkup_log.[type] = N'L'
               and bkup_log.[backup_finish_date] = ( (select  max([backup_finish_date])
               from    [msdb]..[backupset] b2  where   b2.[database_name] = bkup_full.[database_name]                                                                                                    and b2.[server_name] = bkup_full.[server_name]                                                                                                    and b2.[type] = N'L') )
            left join [msdb]..[backupset] as bkup_diff on bkup_diff.[database_name] = bkup_full.[database_name]
               and bkup_diff.[server_name] = bkup_full.[server_name]                                                     
               and bkup_diff.[type] = N'I'
               and bkup_diff.[backup_finish_date] = ( (select max([backup_finish_date])
                 from    [msdb]..[backupset] b2
                 where   b2.[database_name] = bkup_full.[database_name]
                 and b2.[server_name] = bkup_full.[server_name]
                 and b2.[type] = N'I') )
                 where   bkup_full.[type] = N'D'
                and bkup_full.[backup_finish_date] = ( (select  max([backup_finish_date])
                       from   [msdb]..[backupset] b2
                       where  b2.[database_name] = bkup_full.[database_name]
                       and b2.[server_name] = bkup_full.[server_name]
                                                        and b2.[type] = N'D') )
            and exists ( select [name]
                         from   [master]..[sysdatabases]
                         where  [name] = bkup_full.[database_name] )
            and bkup_full.[database_name] <> N'tempdb'

HostForLIFE.eu SQL Server 2014 Hosting
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 customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



SQL Server 2014 Hosting Germany - HostForLIFE.eu :: How to List All Tables of a Linked Server's Database ?

clock January 20, 2015 05:04 by author Peter

There are numerous situations in the DBMSs  world where you may need to utilize a connected server between two diverse SQL Server 2014 cases with a specific end goal to execute immediate queries between them. In any case, the majority of T-SQL auto-complete tools experience issues to rundown the items (i.e. tables) of the connected server's database.

An approach to see these items, is to browse via SSMS's Object Explorer. Shouldn't we think about however in the event that you need to have a quick view of all the accessible tables in the connected server's database while composing your T-SQL script?

The answer is simple! You can do this by utilizing the Information Schema Views. Underneath you will discover a pstored procedure that I made which can help you to list  all the tables of linked server's database. And here is the code:
------------------------------------------------------------------------------------------
-- Sample Code for Blog Post: Listing all Tables of a Linked Server's Database
-- Disclaimer: This is a sample code. Do not use it in Production Systems before properly
-- Testing it. You bear sole responsibility for usage of any content of this T-SQL code.
-- You are responsible for any loss of data, loss of peace or any damages due to usage of this code. Always take backup of your data.
------------------------------------------------------------------------------------------
USE [ENTER_DATABASE_NAME];
GO
CREATE PROCEDURE [dbo].[DBTableInfo] (@LinkedServerName varchar(50), @DBName varchar(50))
AS
--variables declaration
DECLARE @LinkedServerNameFiltered VARCHAR(50)
DECLARE @LinkedServerNameFound int
DECLARE @DBsFound int
DECLARE @DBNameFiltered varchar(50)
DECLARE @Command nvarchar(500)
--check if specified linked server exists
SET @LinkedServerNameFiltered=QUOTENAME(@LinkedServerName);
SET @LinkedServerNameFound=0;
SET @LinkedServerNameFound=(SELECT COUNT(*) FROM sys.servers s WHERE s.name=@LinkedServerName);
--report findings
IF @LinkedServerNameFound=0
BEGIN
PRINT 'Error: Linked server ' + @LinkedServerNameFiltered+ ' not found.';
RETURN;
END
--check if specified database exists
DECLARE @QUERY nvarchar(250);
SET @DBNameFiltered = QUOTENAME(@DBName,'''');
SET @DBsFound=0;
SET @QUERY='(SELECT @DBs=COUNT(*) FROM ' + @LinkedServerNameFiltered +'.[master].sys.sysdatabases s WHERE s.name='+@DBNameFiltered+')';
EXEC sp_executesql @QUERY, N'@DBs int OUTPUT', @DBs=@DBsFound OUTPUT;
--report findings
IF @DBsFound=0
BEGIN
PRINT 'Error: Database ' + @DBNameFiltered + ' not found.';
RETURN;
END
--construct dynamic T-SQL statement
SET @DBNameFiltered = QUOTENAME(@DBName);
SET @LinkedServerNameFiltered=QUOTENAME(@LinkedServerName);
SET @Command= 'SELECT TABLE_SCHEMA as TableSchema, TABLE_NAME as TableName,(''SELECT TOP 10 * FROM '+ @LinkedServerNameFiltered +'.'+ @DBNameFiltered +'.'' + QUOTENAME(TABLE_SCHEMA) + ''.'' + QUOTENAME(TABLE_NAME)) as SampleQuery
FROM ' + @LinkedServerNameFiltered+'.' + @DBNameFiltered+'.INFORMATION_SCHEMA.TABLES i WHERE i.TABLE_TYPE LIKE ''%TABLE%'' ORDER BY 1';
--execute the command
EXEC sp_executesql @command;
------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------

You can call the stored procedure as follows:
USE [ENTER_DATABASE_NAME];
GO
EXEC [dbo].[DBTableInfo] 'LINKED_SERVER_NAME', 'LINKED_SERVER_DB'
GO


The stored procedure shows three columns for each each record:(i) Table Schema, (ii) Table Name, (iii) A sample question that can be executed and gives back where the top 10 rows for the specific table.. And here is the output:

HostForLIFE.eu SQL Server 2014 Hosting
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 customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



Node.js Hosting UK - HostForLIFE.eu :: Creating HTTPS Server With Node.js

clock January 15, 2015 07:04 by author Peter

HTTP server was ok for us to try and do numerous operations that we've performed within the articles lately. During this specific article however, we are going to be looking at a way to create HTTPS server instead with Node.js.

We use HTTPS after we would like secure sessions. A secure session implies that the online browser can encrypt everything you are doing with a digitally signed certificate. Therefore clearly before you are doing HTTPS, you would like to make certificates. Let's therefore spend a while to check a way to develop certificates for SSL.

Make a SSL Certificates
In order to make a certificate, you need to download a small tool OpenSSL first from this link https://code.google.com/p/openssl-for-windows/downloads/list

Download the version as per your system's specification, it's essentially a zip file. Once downloaded, extract the content to a such location onto your disc drive. Now open the location of the extracted content and copy the file openssl.cnf to the bin folder.

That is the configuration file for the Openssl. Next, open CMD, change the directory to this folder and execute the following code.

openssl req -config openssl.cnf -x509 -days 365 -newkey rsa:1024 -keyout hostkey.pem -nodes -out hostcert.pem

The program can then a few you for a few peices of data for creating the certificate. in the end of everything, you may have 2 files hostcert.pem and hostkey.pem, that is our certificate and key file respectively, that we are going to be using in our HTTPS server.

Creating HTTPS server
Just like we have a tendency to do for HTTP, an import to node's HTTP module, for HTTPS we import the HTTPS module. Also, since we'd like to pass within the certificate and key file, we also need to import the filestream (fs) module to enable Node to read the files. the following is that the code to make the HTTPS server.
var https = require('https'); 
var fs = require('fs'); 
   var options = { 
  key: fs.readFileSync('hostkey.pem'), 
  cert: fs.readFileSync('hostcert.pem') 
}; 
https.createServer(options, function (req, res) { 
 res.writeHead(200); 
  res.end("hello world\n"); 
}).listen(8000); 


Of course you wish to copy the files into the same location because the node program. now if you explore the code above, you will find that it's very similar to what we discussed before, like reading files, making a http server so on. The change however is that the https.createServer() method that takes another parameter, that is that the certificate and key for the SSL.

Now if you run the code and see it in a browser, this can be how it looks:
Select proceed anyway option as of now, as our browser does not understand our amazing certificate.



SQL Server 2012 Hosting Spain - HostForLIFE.eu :: How to to check Recovery Model of a database in SQL Server ?

clock January 13, 2015 06:34 by author Peter

A Recovery Model is property of a database that control how transaction log is maintained. SQL Server supports simple, FULL and BULK-LOGGED recovery models. There are multiple ways in which to check recovery model of a database in SQL Server.

1. Using SQL Server Management Studio:
Right click on database in Object explorer -> Go to Properties dialog box -> Options page -> Recovery model

2. Using Metadata function – DATABASEPROPERTYEX():
SELECT [RecoveryModel] = DATABASEPROPERTYEX('SqlAndMe','Recovery')
GO 


Result Set: 
RecoveryModel
SIMPLE 

3. Using catalog view – sys.databases:
SELECT [DatabaseName] = name,
       [RecoveryModel] = recovery_model_desc
FROM   sys.databases
GO  


Result Set:
DatabaseName   RecoveryModel
master         SIMPLE
tempdb         SIMPLE
model          FULL
msdb           SIMPLE
Pubs           SIMPLE
EuWindows      SIMPLE
TestDB         SIMPLE
ProductCatalog SIMPLE
ReportDemo     SIMPLE
ReportServer   FULL
ReportServerTempDB  SIMPLE

(11 row(s) affected)

Using sys.databases catalog view is easier as it returns information of all databases on server. Hope this tutorial works for you!

 



SQL Server 2012 Hosting UK - HostForLIFE.eu :: Number of words in a string on SQL Server

clock January 9, 2015 06:01 by author Peter

In SQL Server there is not any inherent capacity accessible for discovering the number of words in a String. Here I reveal to both of you diverse methodologies for doing this, the first is the most simpleone, and is applicable only of these words are separated by a single space.

DECLARE @String VARCHAR(4000)
SELECT @String = 'SQL Server 2005'
SELECT LEN(@String) - LEN(REPLACE(@String, ' ', '')) + 1

As I said prior, the above query will provides for you the right result, just if the words are differentiated with a solitary space. Presently on the off chance that they are differentiated by more than one space, this will provide for you off base results as the results are basically relied on upon  Length of the original string. Along these lines, what will be the arrangement, simply compose a function  to do this.

CREATE FUNCTION dbo.udfWordCount(
@OriginalText VARCHAR(8000)
)
RETURNS int
as
/*
SELECT dbo.udfWordCount ('hello   world')
*/
BEGIN
    DECLARE @i int ,@j INT, @Words int
    SELECT     @i = 1, @Words = 0
    WHILE @i <= DATALENGTH(@OriginalText)
    BEGIN
        SELECT    @j = CHARINDEX(' ', @OriginalText, @i)
       if @j = 0
        BEGIN
            SELECT    @j = DATALENGTH(@OriginalText) + 1
        END
        IF SUBSTRING(@OriginalText, @i, @j - @i) <>' '
              SELECT @Words = @Words +1
        SELECT    @i = @j +1
    END
    RETURN(@Words)
END
GO
SELECT dbo.udfWordCount ('SQL Server2012')
SELECT dbo.udfWordCount ('SQL Server 2012 ')

 



SQL Server 2014 Hosting Russia - HostForLIFE.eu :: Restart Interrupted Restore Operations

clock January 8, 2015 07:19 by author Peter

Circumstances in which a restore operation is hindered are not exceptionally remarkable. This is the reason, in this post, we will demonstrate to you what you need to do with a specific end goal to restart the interrupted operation using T-SQL queries in SQL Server 2014.

In the event that your restore operation was interrupted, you can at present restart the methodology and proceed starting there where it got intruded.

This is a peculiarity that can be extremely valuable in the event that you have huge databases which you need to restore. On the off chance that the methodology of restoring falls flat near to the end, the majority of the times you can restart the whole operation from the point where it cleared out off, as opposed to restarting the whole restore procedure of the database.

To be particular, when you make your restore from tape, you can restart from the current tape as opposed to restarting from the first. Anyhow, if the restore was in the stage when it was being rolled forward, then no information will be replicated from that backup set.

Restart interrupted restore with T-SQL
In the event that you have utilized a T-SQL query to restore your database and the methodology was hindered for any reason, known or obscure, then what you need to do is to define a RESTART proviso toward the end of the same inquiry and run the question yet again.

Let’s assume that you have the following query, or something similar, and it got interrupted during execution.
-- Restore a full database backup of myDB database
RESTORE DATABASE myDB
FROM DISK = 'C:\myDB.bak'
GO

Presently, keeping in mind the end goal to proceed with and interrupted restore operations, connected for our situation, we are going to utilize the query from above completed with the WITH RESTART clause.

-- Just run the initial RESTORE statement specifying WITH RESTART in order to restart interrupted restore operations
RESTORE DATABASE myDB
FROM DISK = 'C:\myDB.bck'
WITH RESTART
GO



SQL Reporting Service (SSRS) 2014 Hosting - HostForLIFE.eu :: How to Get the List of All Reports Using the Query ?

clock January 6, 2015 05:34 by author Peter

This can be a decent administrator device to screen all reports create on SSRS case and it can be helpful particularly if the rundown of your reports is getting huge.  It's a basic question on "Reportserver" database which can be once in a while named differently much the same as mine is: "Reportserver$mike" (named occasions), yet for SSRS introduced on default case it ought to be this one from beneath:

USE [ReportServer]
GO
SELECT
  Name,
  [Path]
  --,[Description]
FROM [dbo].[Catalog]
WHERE [Type] = 2
ORDER BY [Path]


Result:
Name Path
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
AdventureWorks_Base /AdventureWorks/AdventureWorks_Base
Customers_Near_Stores /AdventureWorks/Customers_Near_Stores
Employee_Sales_Summary /AdventureWorks/Employee_Sales_Summary
Sales_by_Region /AdventureWorks/Sales_by_Region
Sales_Order_Detail /AdventureWorks/Sales_Order_Detail
Store_Contacts /AdventureWorks/Store_Contacts
(6 row(s) affected)


Likewise, here is a little extensio for the query which I want to utilize this one with guardian envelope structure included:
USE [ReportServer]
GO
SELECT
  Name,
  FullPath = [Path]
  ,ReportParentPath = REVERSE(SUBSTRING(REVERSE(Path), CHARINDEX('/', REVERSE(Path)), LEN(REVERSE(Path))))
  --,[Description]
FROM [dbo].[Catalog]
WHERE [Type] = 2
ORDER BY [Path]


For more extensive checking contemplations I prescribe probably the most vital tables in Reportserver database: USE [ReportServer]
GOSELECT * FROM [Catalog]
SELECT * from [dbo].[DataSets]
SELECT * FROM [dbo].[DataSource]
SELECT * FROM [dbo].[Users]



HostForLIFE.eu Proudly Launches DotNetNuke 7.3.4 Hosting

clock December 23, 2014 07:46 by author Peter

European leading web hosting provider, HostForLIFE.eu announced support for DotNetNuke 7.3.4 hosting plan due to high demand of DotNetNuke CMS users in Europe.

HostForLIFE.eu proudly launches the support of DotNetNuke 7.3.4 on all our newest Windows Server  environment. HostForLIFE.eu DotNetNuke 7.3.4 Hosting plan starts from just as low as €3.00/month only and this plan has supported ASP.NET 5, ASP.NET MVC 5/6 and SQL Server 2012/2014.

DotNetNuke 7.3.4, as well known in the web industry and familiar among .NET developers, is a Web Content Management System (WCMS) based on Microsoft .NET platform. It is an excellent open source software that you can use to manage your website without having much technical knowledge.

HostForLIFE.eu clients are specialized in providing supports for DotNetNuke for many years. We are glad to provide support for European DotNetNuke 7.3.4 hosting users with advices and troubleshooting for our clients website when necessary.

DNN 7.3.4 is a smaller maintenance release than normal and is focused on addressing the most serious platform issues. DNN 7.3.4 addresses a number of platform issues and should be the last release before DNN 7.4.0. DNN 7.3.4 added ability to save localized lists to resource file, added method to remove all subscriptions from a ContentItem, fixed issue where AUM was not correctly handling 301 redirects, Fixed issue where popup iframe is not initialized correctly and fixed issue where multiple region/country controls in a profile did not work correctly.

DotNetNuke 7.3.4 will be a great content management system that support many advance website features such as blogs, forums, e-commerce system, photo galleries and more. DotNetNuke 7.3.4 is a great platform to build your web presence with. HostForLIFE.eu can help customize any web software that company wishes to utilize.

Further information and the full range of features DotNetNuke 7.3.4 Hosting can be viewed here http://www.hostforlife.eu/European-DotNetNuke-734-Hosting

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

HostForLIFE.eu is awarded Top No#1 SPOTLIGHT Recommended Hosting Partner by Microsoft (see http://www.asp.net/hosting/hostingprovider/details/953). Our service is ranked the highest top #1 spot in several European countries, such as: Germany, Italy, Netherlands, France, Belgium, United Kingdom, Sweden, Finland, Switzerland and other European countries.



Kentico 8.1 Hosting Italy - HostForLIFE.eu :: Smart Search Index Rebuilding Scheduled Task in Kentico 8.1

clock December 18, 2014 11:18 by author Peter

During my recents projects in Kentico 8.1, I had to tack together the search engine to own search fields on the web site. The search engine included in Kentico is Lucene, a full text search engine supported physical files indexes. For every web site, you wish to build on rebuild basis the different search indexes you define in Kentico. During this case, I assumed that the regular Task "Optimize search indexes", defined by default in Kentico, was doing this calculation of search indexes. My assumption was wrong, there's actually no regular task doing the index rebuilding.

So, because we did not wish to log every night to my sites to launch manually each index rebuilding, I enforced my own scheduled task for doing it, here is the source code :

using System;
using CMS.EventLog;
using CMS.Scheduler;
using CMS.SiteProvider;
using System.Data;
namespace MyProject.Services.ScheduledTasks
{
    public class SmartSearchReIndexTask: ITask
    {
        private const string Name = "SmartSearchReIndexTask";
        public string Execute(TaskInfo task)
        {
            var response = " Reindexing smart search updated successfully.
";
            const string eventCode = "Smart Search Execution";           
           try
            {
                //retrieve Planet search indexes

                EventLogProvider.LogInformation(Name, eventCode, "Start reindexing");
                DataSet indexes = SearchIndexInfoProvider.GetSearchIndexes("IndexName LIKE N'MyProject%'", null);
                if (indexes != null)
                {
                    foreach (DataTable table in indexes.Tables)
                   {
                        foreach (DataRow row in table.Rows)
                        {
                            //create a reindex task for that search index
                           
SearchIndexInfo searchIndexInfo = SearchIndexInfoProvider.GetSearchIndexInfo(Convert.ToInt32(row.ItemArray[0]));  
//row.ItemArray[0] is the SearchIndex ID
                            if (searchIndexInfo != null)
                            {
                                SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, searchIndexInfo.IndexType, null, searchIndexInfo.IndexName);                               
System.Threading.Thread.Sleep(100);
                                EventLogProvider.LogInformation(Name, eventCode, string.Format("Recalculating the index: {0}", searchIndexInfo.IndexName));
                            }
                        }
                    }
                }
                EventLogProvider.LogInformation(Name, eventCode, response);               
            }
            catch (Exception ex)
           {
                response = "Error reindexing smart search . Check the event log for more information.";
                EventLogProvider.LogException(Name, eventCode, ex);
            }
            return response;
        }
    }
}

Put this code in a library, put this library in the bin folder of your Kentico 8.1 site and then configure a new custom task.



SQL Server 2012 Hosting UK - HostForLIFE.eu :: Remove the Special Characters in a String

clock December 16, 2014 07:30 by author Peter

Today, I am going to tell you how to replace the special characters in a string with spaces. In this case, I need to use PATINDEX.

PATINDEX
It will returns the starting position of the first occurrence of a pattern in a specified expression, or zeros if the pattern is not found, on all valid text and character data types. And this is the code that I used:
PATINDEX ( '%pattern%' , expression )

Example:
DECLARE @Str varchar(100)
SET @Str='Welcome!@+to+#$%SQL+^&*(SERVER)_+'
SELECT PATINDEX('%SQL%', @Str)


Here is the result from that code:

Remove Special Characters from String in SQL Server DECLARE @regexp INT
DECLARE @Str varchar(100)
SET @Str='Welcome!@+to+#$%SQL+^&*(SERVER)_+   '
SET @regexp = PATINDEX('%[^a-zA-Z0-9 ]%', @Str)
WHILE @regexp > 0
BEGIN
SET @Str = STUFF(@Str, @regexp, 1, ' ' )
SET @regexp = PATINDEX('%[^a-zA-Z0-9 ]%', @Str)
Print @regexp
END
SELECT @Str


Result
:

STUFF
This STUFF function inserts a string into another string. It deletes a specified length of characters in the first string at the start position and then inserts the second string into the first string at the start position. This is the code:
STUFF ( character_expression , start , length , replaceWith_expression )


Example:
DECLARE @regexp INT
DECLARE @Str varchar(100)
SET @Str='welcome to sql server'
SET @Str = STUFF(@Str, 1, 1, '@' )
Select @str 



About HostForLIFE

HostForLIFE 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 2019 Hosting, ASP.NET 5 Hosting, ASP.NET MVC 6 Hosting and SQL 2019 Hosting.


Month List

Tag cloud

Sign in