European Windows 2012 Hosting BLOG

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

SQL Reporting Service (SSRS) 2012 Hosting - HostForLIFE.eu ::: How to Access SSRS with Fully Qualified Domain Name?

clock October 13, 2015 11:24 by author Peter

If you installed SQL Server reporting Services (SSRS) on a server in a domain and you utilize a website user to start out the service and did not perform any further configuration, then you likely will only access the Report Manager using an IP and not the fully Qualified domain name (FQDN) of the server (if an SPN isn't set).

If you are trying to use the fully Qualified domain name to access reporting services then you may likely be prompted for username password several times ending with an empty page.

In order to be able to access reporting Services using FQDN you may need to perform the subsequent actions:
1. Register a Service Principal Name (SPN) for the Domain User Account that Runs SSRS
Please look at the following example:
sample computer name: testssrs01
sample domain: example.com
sample domain account: example\ssrsuser


Next, on the Domain Controller Server in a Command Prompt with Elevated Rights, you can Run as Administrator:
Example 1:
If SSRS are on port 80 (no need to specify 80 as it is the default http port):
Setspn -s http/testssrs01.example.com example\ssrsuser

Example 2:
If SSRS are on any other port (i.e. 2430):
Setspn -s http/testssrs01.example.com:2430 example\ssrsuser

2. Edit the RsReportServer.config File
On the Reporting Services server, in the virtual directory of SSRS, edit the "RsReportServer.config" file and locate the authenticationtypes section. Then add /rswindowsnegotiate as the first entry in the authenticationtypes section.

This above step will actually enable NTLM.

HostForLIFE.eu SQL Reporting Service (SSRS) 2012 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.



AngularJS Hosting - HostForLIFE.eu :: User Validation with Bootstrap in AngularJS

clock October 8, 2015 12:11 by author Peter

AngularJS forms and controls can validate input data. AngularJS forms and controls can provide validation services, and notify users of invalid input. In this tutorial, we will learn how to perform user validation with bootstrap in AngularJS.

HTML code
var app = angular.module('myapp', ['UserValidation']); 
myappCtrl = function($scope) { 
$scope.formAllGood = function () { 
return ($scope.usernameGood && $scope.passwordGood && $scope.passwordCGood) 




angular.module('UserValidation', []).directive('validUsername', function () { 
return { 
require: 'ngModel', 
link: function (scope, elm, attrs, ctrl) { 
ctrl.$parsers.unshift(function (viewValue) { 
    // Any way to read the results of a "required" angular validator here? 
    var isBlank = viewValue === '' 
    var invalidChars = !isBlank && !/^[A-z0-9]+$/.test(viewValue) 
    var invalidLen = !isBlank && !invalidChars && (viewValue.length < 5 || viewValue.length > 20) 
    ctrl.$setValidity('isBlank', !isBlank) 
    ctrl.$setValidity('invalidChars', !invalidChars) 
    ctrl.$setValidity('invalidLen', !invalidLen) 
    scope.usernameGood = !isBlank && !invalidChars && !invalidLen 

}) 


}).directive('validPassword', function () { 
return { 
require: 'ngModel', 
link: function (scope, elm, attrs, ctrl) { 
ctrl.$parsers.unshift(function (viewValue) { 
    var isBlank = viewValue === '' 
    var invalidLen = !isBlank && (viewValue.length < 8 || viewValue.length > 20) 
    var isWeak = !isBlank && !invalidLen && !/(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z])/.test(viewValue) 
    ctrl.$setValidity('isBlank', !isBlank) 
    ctrl.$setValidity('isWeak', !isWeak) 
    ctrl.$setValidity('invalidLen', !invalidLen) 
    scope.passwordGood = !isBlank && !isWeak && !invalidLen 

}) 


}).directive('validPasswordC', function () { 
return { 
require: 'ngModel', 
link: function (scope, elm, attrs, ctrl) { 
ctrl.$parsers.unshift(function (viewValue, $scope) { 
    var isBlank = viewValue === '' 
    var noMatch = viewValue != scope.myform.password.$viewValue 
    ctrl.$setValidity('isBlank', !isBlank) 
    ctrl.$setValidity('noMatch', !noMatch) 
    scope.passwordCGood = !isBlank && !noMatch 
}) 


}) 

JAVASCRIPT Code

var app = angular.module('myapp', ['UserValidation']); 

myappCtrl = function($scope) { 
$scope.formAllGood = function () { 
return ($scope.usernameGood && $scope.passwordGood && $scope.passwordCGood) 




angular.module('UserValidation', []).directive('validUsername', function () { 
return { 
require: 'ngModel', 
link: function (scope, elm, attrs, ctrl) { 
ctrl.$parsers.unshift(function (viewValue) { 
    // Any way to read the results of a "required" angular validator here? 
    var isBlank = viewValue === '' 
    var invalidChars = !isBlank && !/^[A-z0-9]+$/.test(viewValue) 
    var invalidLen = !isBlank && !invalidChars && (viewValue.length < 5 || viewValue.length > 20) 
    ctrl.$setValidity('isBlank', !isBlank) 
    ctrl.$setValidity('invalidChars', !invalidChars) 
    ctrl.$setValidity('invalidLen', !invalidLen) 
    scope.usernameGood = !isBlank && !invalidChars && !invalidLen 

}) 


}).directive('validPassword', function () { 
return { 
require: 'ngModel', 
link: function (scope, elm, attrs, ctrl) { 
ctrl.$parsers.unshift(function (viewValue) { 
    var isBlank = viewValue === '' 
    var invalidLen = !isBlank && (viewValue.length < 8 || viewValue.length > 20) 
    var isWeak = !isBlank && !invalidLen && !/(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z])/.test(viewValue) 
    ctrl.$setValidity('isBlank', !isBlank) 
    ctrl.$setValidity('isWeak', !isWeak) 
    ctrl.$setValidity('invalidLen', !invalidLen) 
    scope.passwordGood = !isBlank && !isWeak && !invalidLen 

}) 


}).directive('validPasswordC', function () { 
return { 
require: 'ngModel', 
link: function (scope, elm, attrs, ctrl) { 
ctrl.$parsers.unshift(function (viewValue, $scope) { 
    var isBlank = viewValue === '' 
    var noMatch = viewValue != scope.myform.password.$viewValue 
    ctrl.$setValidity('isBlank', !isBlank) 
    ctrl.$setValidity('noMatch', !noMatch) 
    scope.passwordCGood = !isBlank && !noMatch 
}) 


}) 


If you fill with the wrong detail then it'll give the error like the following picture:

HostForLIFE.eu AngularJS 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.



SQL Server 2014 Hosting - HostForLIFE.eu :: How to Check Database Size in SQL Server 2014?

clock September 22, 2015 11:26 by author Peter

Sometimes we'd like to understand how much space utilized by databases in SQL Server. There are multiple ways that to know the database size in SQL SERVER.
1. using Table Sys.master_files
2. using stored Proc sp_spaceused
3. using Manual option in SSMS

Using Table Sys.master_files
This is one option by that we will know database size. Below query uses 2 tables databases that contains database ID, Name etc and another table master_files which contains size columns holds size of database. By using Inner join(database ID) we are getting database size. each tables are present in master database.
SELECT     sys.databases.name, 
           CONVERT(VARCHAR,SUM(size)*8/1024)+' MB' AS [Total disk space] 
FROM       sys.databases  
JOIN       sys.master_files 
ON         sys.databases.database_id=sys.master_files.database_id 
GROUP BY   sys.databases.name 
ORDER BY   sys.databases.name


See the following picture after executing above code which gives all the databases with their sizes.

Using stored Proc sp_spaceused 

This  is second choice to recognize database size. Here we are going to call stored procedure sp_spaceused which is present in master database. This one helps to know size of current database.
exec sp_spaceused  

After calling above stored procedure it shows  below Image2 which contains column called database_size surrounded by red mark.

Using Manual Option in SSMS
This is another option to know database size. To know size Go to Server Explorer -> Expand it -> Right click on Database -> Choose Properties -> In popup window choose General tab ->See Size property which is marked(red) in Image3.

Image 3: Manual option to get Database size
Hope it helps you to get database size in SQL Server!

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.



SQL Server 2012 Hosting - HostForLIFE.eu :: How to Create a User Defined Error Message in SQL Server?

clock September 14, 2015 07:33 by author Peter

In this article I describe the way to produce a User defined error message in SQL Server 2012. we use SP_addmessage to add a custom message and after that we have a tendency to use a RAISERROR Statement to invoke the custom message. We use the SP_admessage stored Procedure to define a User defined Custom Error Message. This stored Procedure adds a record to the sys.message system view. A User defined message should have a message number of 50000 or higher with a severity of 1 to 25. And here is the code:
sp_addmessage [ @msgnum = ] msg_id ,
[ @severity = ] severity ,
[ @msgtext = ] 'msg'
[ , [ @lang = ] 'language' ]
[ , [ @with_log = ] 'with_log' ]
[ , [ @replace = ] 'replace' ]

Here mcg_id is that the id of the message which might be between 50000 and 2147483647. The severity is the level of the message which might be between one and twenty five. For User defined messages we are able to use it a value of 0 to 19. The severity level between 20 to 25 may be set by the administrator. Severity levels from 20 through 25 are considered fatal.

The actual error message is "msg", that uses a data type of nvarchar(255). the maximum characters limit is two,047. any more than that will be truncated. The language is used if you wish to specify any language. Replace is used once a similar message number already exists, however you wish to switch the string for that ID, you've got to use this parameter.

RAISERROR:
The RAISERROR statement generates an error message by either retrieving the message from the sys.messages catalog read or constructing the message string at runtime. it's used to invoke the the User defined error message. first we produce a User defined error message using SP_addmessage and after that we invoke that by the use of RAISERROR.
RAISERROR ( { msg_id  }
{ ,severity ,state }
[ ,argument [ ,...n ] ] )
[ WITH option [ ,...n ] ]


Example:
EXEC sp_addmessage
500021,
10,
'THis is error message'
go
RAISERROR (500021, 10, 1)


Replacement of Message.
EXEC sp_addmessage
500021,
10,
'Previous error message is replaced',
@lang='us_english',
@with_log='false',
@replace='replace'
GO
RAISERROR (500021, 10, 1)


Altering the message:
exec sp_altermessage 500021,@parameter='with_log', @parameter_value='true'

Droping the message:
exec sp_dropmessage 500021

HostForLIFE.eu SQL Server 2012 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.



HostForLIFE.eu Proudly Launches ASP.NET 4.6 Hosting

clock September 7, 2015 12:38 by author Peter

HostForLIFE.eu was established to cater to an underserved market in the hosting industry; web hosting for customers who want excellent service. HostForLIFE.eu – a cheap, constant uptime, excellent customer service, quality, and also reliable hosting provider in advanced Windows and ASP.NET technology. HostForLIFE.eu proudly announces the availability of the ASP.NET 4.6 hosting in their entire servers environment.

http://hostforlife.eu/img/logo_aspnet1.png

ASP.NET is Microsoft's dynamic website technology, enabling developers to create data-driven websites using the .NET platform and the latest version is 5 with lots of awesome features. ASP.NET 4.6 is a lean .NET stack for building modern web apps. Microsoft built it from the ground up to provide an optimized development framework for apps that are either deployed to the cloud or run on-premises. It consists of modular components with minimal overhead.

According to Microsoft officials, With the .NET Framework 4.6, you'll enjoy better performance with the new 64-bit "RyuJIT" JIT and high DPI support for WPF and Windows Forms. ASP.NET provides HTTP/2 support when running on Windows 10 and has more async task-returning APIs. There are also major updates in Visual Studio 2015 for .NET developers, many of which are built on top of the new Roslyn compiler framework. The .NET languages -- C# 6, F# 4, VB 14 -- have been updated, too.There are many great features in the .NET Framework 4.6. Some of these features, like RyuJIT and the latest GC updates, can provide improvements by just installing the .NET Framework 4.6.

HostForLIFE.eu hosts its servers in top class data centers that is located in Amsterdam (NL), London (UK), Paris (FR), Frankfurt(DE) and Seattle (US) to guarantee 99.9% network uptime. All data center feature redundancies in network connectivity, power, HVAC, security, and fire suppression. All hosting plans from HostForLIFE.eu include 24×7 support and 30 days money back guarantee. The customers can start hosting their ASP.NET 4.6 site on their environment from as just low €3.00/month only.

HostForLIFE.eu is a popular online ASP.NET based hosting service provider catering to those people who face such issues. The company has managed to build a strong client base in a very short period of time. It is known for offering ultra-fast, fully-managed and secured services in the competitive market.

HostForLIFE.eu offers the latest European ASP.NET 4.6 hosting installation to all their new and existing customers. The customers can simply deploy their ASP.NET 4.6 website via their world-class Control Panel or conventional FTP tool. HostForLIFE.eu is happy to be offering the most up to date Microsoft services and always had a great appreciation for the products that Microsoft offers.

Further information and the full range of features ASP.NET 4.6 Hosting can be viewed here http://hostforlife.eu/European-ASPNET-46-Hosting



HostForLIFE.eu Launches Umbraco 7.2.8 Hosting

clock August 19, 2015 06:57 by author Peter

HostForLIFE.eu, a leading web hosting provider, has leveraged its gold partner status with Microsoft to launch its latest Umbraco 7.2.8 Hosting support

HostForLIFE.eu, a leading Windows web hosting provider with innovative technology solutions and a dedicated professional services team, today announced the support for Umbraco 7.2.8 hosting plan due to high demand of Umbraco users in Europe. The company has managed to build a strong client base in a very short period of time. It is known for offering ultra-fast, fully-managed and secured services in the competitive market.

HostForLIFE.eu hosts its servers in top class data centers that is located in Amsterdam (NL), London (UK), Paris (FR), Frankfurt (DE) and Seattle (US) to guarantee 99.9% network uptime. All data center feature redundancies in network connectivity, power, HVAC, security and fire suppression. All hosting plans from HostForLIFE.eu include 24×7 support and 30 days money back guarantee. HostForLIFE Umbraco hosting plan starts from just as low as €3.00/month only and this plan has supported ASP.NET 4.5, ASP.NET MVC 5/6 and SQL Server 2012/2014.

Umbraco 7.2.8 is a fully-featured open source content management system with the flexibility to run anything from small campaign or brochure sites right through to complex applications for Fortune 500's and some of the largest media sites in the world. Umbraco was sometimes unable to read the umbraco.config file, making Umbraco think it had no content and showing a blank page instead (issue U4-6802), this is the main issue fixed in this release. This affects people on 7.2.5 and 7.2.6 only. 7.2.8 also fixes a conflict with Courier and some other packages.

Umbraco 7.2.8 Hosting is strongly supported by both an active and welcoming community of users around the world, and backed up by a rock-solid commercial organization providing professional support and tools. Umbraco 7.2.8 can be used in its free, open-source format with the additional option of professional tools and support if required. Not only can you publish great multilingual websites using Umbraco 7.2.8 out of the box, you can also build in your chosen language with our multilingual back office tools.

Further information and the full range of features Umbraco 7.2.8 Hosting can be viewed here: http://hostforlife.eu/European-Umbraco-728-Hosting

About HostForLIFE.eu

HostForLIFE.eu is an European Windows Hosting Provider which focuses on the 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). Their 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. Besides this award, they have also won several awards from reputable organizations in the hosting industry and the detail can be found on their official website.



AngularJS Hosting - HostForLIFE.eu :: Learn How to Make a Directive to Allow only Numbers using AngularJs

clock August 5, 2015 08:36 by author Peter

Before reading this text there is only one prerequisite condition; you must know how to create a directive in AngularJs and why we need to create them. First of all you need to add AngularJs and jQuery to your page, similar to here:
<head runat="server"> 
<title></title> 
<script src="angular.min.js"></script> 
<script src="jquery-1.11.1.min.js"></script> 
</head>

You will either download them from my code that is available at the start of this article or you can download from their official websites. Now i'm simply adding a textbox wherever i would like to allow only numbers using an AngularJs directive.
<body> 
<form ng-app="app" id="form1" runat="server"> 
<div>
<h3> Demo to Allow Numbers Only </h3>
<hr /> 
Provide Your Mobile Number: <input type="text" 
name="MobileNumber" 
class="form-control" 
allow-only-numbers /> 
<hr /> 
</div> 
</form> 
</body>

Now it's time for Angular code. Write the following code:
<script> 
var app = angular.module('app', []); 
app.directive('allowOnlyNumbers', function () { 
return { 
restrict: 'A', 
link: function (scope, elm, attrs, ctrl) { 
elm.on('keydown', function (event) { 
if (event.which == 64 || event.which == 16) { 
// to allow numbers 
return false; 
} else if (event.which >= 48 && event.which <= 57) { 
// to allow numbers 
return true; 
} else if (event.which >= 96 && event.which <= 105) { 
// to allow numpad number 
return true; 
} else if ([8, 13, 27, 37, 38, 39, 40].indexOf(event.which) > -1) { 
// to allow backspace, enter, escape, arrows 
return true; 
} else { 
event.preventDefault(); 
// to stop others 
return false; 

}); 


}); 
</script>


Here I first created a module named "app". The module creation is a necessary part if you wish to use Angular. This module is added to the HTML page using the ng-app directive. Then I created the directive with the name "allowOnlyNumbers". If you're making any kind of directive using AngularJs then you need to continually check that the name is provided using "-" in your HTML page and these dashes "-" are replaced by capital letters in the Angular code. Since I had applied this directive to the attribute of the textbox I had restricted this directive using "A" for Attribute.

I had applied this directive on the keydown event of the textbox. After those varied conditions are applied to the ASCII values of the keys to permit or to prevent them. In any case our ASCII values aren't allowed. event.preventDefault() will take away that character and can revert to the previous value. But still I had the intense problem of all the characters that were entered by pressing the shift + key weren't removed by this code, therefore I used easy jQuery at the beginning of the code to help prevent this situation.
var $input = $(this); 
var value = $input.val(); 
value = value.replace(/[^0-9]/g, '') 
$input.val(value); 


Then, write the following code:
app.directive('allowOnlyNumbers', function () { 
return { 
restrict: 'A', 
link: function (scope, elm, attrs, ctrl) { 
elm.on('keydown', function (event) { 
var $input = $(this); 
var value = $input.val(); 
value = value.replace(/[^0-9]/g, '') 
$input.val(value); 
if (event.which == 64 || event.which == 16) { 
    // to allow numbers 
    return false; 
} else if (event.which >= 48 && event.which <= 57) { 
    // to allow numbers 
    return true; 
} else if (event.which >= 96 && event.which <= 105) { 
    // to allow numpad number 
    return true; 
} else if ([8, 13, 27, 37, 38, 39, 40].indexOf(event.which) > -1) { 
    // to allow backspace, enter, escape, arrows 
    return true; 
} else { 
    event.preventDefault(); 
    // to stop others 
    //alert("Sorry Only Numbers Allowed"); 
    return false; 

}); 


}); 


Output:
Now our application is made and we will check the output. On running the application an easy textbox are going to be shown wherever only numbers are allowed.

If you press the numbers from anywhere within the key, they will be allowed however all the other characters won't be allowed to exist, although they're special characters.

HostForLIFE.eu AngularJS 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.



HostForLIFE.eu Launches nopCommerce 3.60 Hosting

clock July 14, 2015 10:53 by author Peter

HostForLIFE.eu, a leading web hosting provider, has leveraged its gold partner status with Microsoft to launch its latest NopCommerce 3.60 Hosting support

European Recommended Windows and ASP.NET Spotlight Hosting Partner, HostForLIFE.eu, has announced the availability of new hosting plans that are optimized for the latest update of the NopCommerce 3.60 hosting technology.

HostForLIFE.eu supports NopCommerce 3.60 hosting on their latest Windows Server and this service is available to all their new and existing customers. nopCommerce 3.60 is a fully customizable shopping cart. It's stable and highly usable. nopCommerce is an open source ecommerce solution that is ASP.NET (MVC) based with a MS SQL 2008 (or higher) backend database. Their easy-to-use shopping cart solution is uniquely suited for merchants that have outgrown existing systems, and may be hosted with your current web hosting. It has everything you need to get started in selling physical and digital goods over the internet.

HostForLIFE.eu Launches nopCommerce 3.60 Hosting

nopCommerce 3.60 is a fully customizable shopping cart. nopCommerce 3.60 provides new clean default theme. The theme features a clean, modern look and a great responsive design. The HTML have been refactored, which will make the theme easier to work with and customize , predefined (default) product attribute values. They are helpful for a store owner when creating new products. So when you add the attribute to a product, you don't have to create the same values again , Base price (PAngV) support added. Required for German/Austrian/Swiss users, “Applied to manufacturers” discount type and Security and performance enhancements.

HostForLIFE.eu hosts its servers in top class data centers that is located in Amsterdam, London, Paris, Seattle (US) and Frankfurt (Germany) to guarantee 99.9% network uptime. All data center feature redundancies in network connectivity, power, HVAC, security, and fire suppression. All hosting plans from HostForLIFE.eu include 24×7 support and 30 days money back guarantee.

All hosting plans from HostForLIFE.eu include 24×7 support and 30 days money back guarantee. The customer can start hosting their NopCommerce 3.60 site on their environment from as just low €3.00/month only. HostForLIFE.eu is a popular online Windows based hosting service provider catering to those people who face such issues. The company has managed to build a strong client base in a very short period of time. It is known for offering ultra-fast, fully-managed and secured services in the competitive market. Their powerful servers are specially optimized and ensure NopCommerce 3.60 performance.

For more information about this new product, please visit http://hostforlife.eu/European-nopCommerce-36-Hosting



SQL Server 2016 Hosting - HostForLIFE.eu :: How to Automate Restore All Transaction log Backup Files ?

clock June 23, 2015 08:13 by author Peter

On one of my servers we had to recover ten databases using last night's full backup and all subsequent log backups. Therefore within the middle of the night it had been about to be huge challenge to manually choose each log backup file to restore. So wrote this script to create commands to restore log backup files which can be then run in an exceedingly query window. Please follow the steps below to use the script.

1. Set the database name to the variable @dbname
2. Copy all the transaction log backups to a new directory. You'll prefer to begin copying the files. That  were taken a couple of minutes before the full backup was taken. You'll choose to copy the last file you wish to be restored based on the recovery point of your time.
3.  In the following line set the directory where you copied the log backup files to.

insert into #dir
exec xp_cmdshell 'dir "C:\Backup\Adventure*.trn" /b'

4. The below code will set the directory to where the log backup files have been copied.
SET @cmd='use master; RESTORE LOG ['+@dbname+'] FROM  DISK =
    N''C:\Backup\'+@filename+''' WITH  FILE = 1,  NORECOVERY,  NOUNLOAD,  STATS = 10'
select (@cmd)

5. Now, Copy the output which should have the RESTORE commands and run them in a new query window.
6. Run the following command to bring the database out of restoring state.

RESTORE DATABASE dbname WITH RECOVERY


############################################################################
use master
set nocount on
DECLARE @filename varchar(2000), @cmd varchar(8000), @dbname varchar(100)

-----------------------Enter the Database name in the next line
SET @dbname='New'

IF  EXISTS (SELECT name FROM tempdb.sys.tables WHERE name like '#dir%')
begin
   DROP table #dir
end
create table #dir (filename varchar(1000))

-----------------------Enter the path to TRN File in the xp_cmdshell line
insert into #dir
exec xp_cmdshell 'dir "C:\Backup\Adventure*.trn" /b'

delete from #dir where filename is null
DECLARE filecursor CURSOR FOR
select * from #dir order by filename asc

OPEN filecursor
FETCH NEXT FROM filecursor INTO @filename

WHILE @@FETCH_STATUS = 0
BEGIN
 SET @cmd='use master; RESTORE LOG ['+@dbname+'] FROM  DISK = N''C:\Backup\'+@filename+''' WITH  FILE = 1,  NORECOVERY,  NOUNLOAD,  STATS = 10'
 print @cmd
FETCH NEXT FROM filecursor INTO @filename
END
CLOSE filecursor 
DEALLOCATE filecursor
drop table #dir

############################################################################

HostForLIFE.eu SQL Server 2016 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.



SQL Server 2016 Hosting - HostForLIFE.eu :: How to Save Picture in SQL Server with ASP.NET ?

clock June 18, 2015 07:18 by author Peter

This article will explains the way to Save pictures In Sqlserver database In Asp.Net using File upload control. I am upload the pictures using FileUpload control and saving or storing them in SQL Server database in ASP.NET with C# and VB.NET.

Database has a table named pictures with 3 columns:
1. ID Numeric Primary key with Identity Increment.
2. ImageName Varchar to store Name of picture.
3. Image column to store image in binary format.

After uploading and saving pictures in database, pics are displayed in GridView. And here is the HTML markup:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtName" runat="server" Width="95px">
</asp:TextBox>
<asp:FileUpload ID="FileUpload1" runat="server"/>
<asp:Label ID="lblMessage" runat="server">
</asp:Label>
<asp:Button ID="btnUpload" runat="server"
            OnClick="btnUpload_Click" Text="Upload"/>
</div>
</form>

Now, write the following code in Click Event of Upload Button:
protected void btnUpload_Click(object sender, EventArgs e)
{
 string strImageName = txtName.Text.ToString();
 if (FileUpload1.PostedFile != null &&
     FileUpload1.PostedFile.FileName != "")
  {
   byte[] imageSize = new byte
                 [FileUpload1.PostedFile.ContentLength];
  HttpPostedFile uploadedImage = FileUpload1.PostedFile;
  uploadedImage.InputStream.Read
     (imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);

 // Create SQL Connection
  SqlConnection con = new SqlConnection();
  con.ConnectionString = ConfigurationManager.ConnectionStrings
                         ["ConnectionString"].ConnectionString;

 // Create SQL Command

 SqlCommand cmd = new SqlCommand();
 cmd.CommandText = "INSERT INTO Images(ImageName,Image)" +
                   " VALUES (@ImageName,@Image)";
 cmd.CommandType = CommandType.Text;
 cmd.Connection = con;

 SqlParameter ImageName = new SqlParameter
                     ("@ImageName", SqlDbType.VarChar, 50);
 ImageName.Value = strImageName.ToString();
 cmd.Parameters.Add(ImageName);

 SqlParameter UploadedImage = new SqlParameter
               ("@Image", SqlDbType.Image, imageSize.Length);
 UploadedImage.Value = imageSize;
 cmd.Parameters.Add(UploadedImage);
 con.Open();
 int result = cmd.ExecuteNonQuery();
 con.Close();
 if (result > 0)
 lblMessage.Text = "File Uploaded";
 GridView1.DataBind();
 }
}


VB.NET Code

Protected Sub btnUpload_Click
(ByVal sender As Object, ByVal e As EventArgs)

    Dim strImageName As String = txtName.Text.ToString()
    If FileUpload1.PostedFile IsNot Nothing AndAlso
       FileUpload1.PostedFile.FileName <> "" Then

        Dim imageSize As Byte() = New Byte
          (FileUpload1.PostedFile.ContentLength - 1) {}

        Dim uploadedImage__1 As HttpPostedFile =
                                 FileUpload1.PostedFile

        uploadedImage__1.InputStream.Read(imageSize, 0,
              CInt(FileUpload1.PostedFile.ContentLength))
       
        ' Create SQL Connection
        Dim con As New SqlConnection()
        con.ConnectionString =
                 ConfigurationManager.ConnectionStrings
                  ("ConnectionString").ConnectionString
       
        ' Create SQL Command
       
        Dim cmd As New SqlCommand()
        cmd.CommandText = "INSERT INTO Images
           (ImageName,Image) VALUES (@ImageName,@Image)"
        cmd.CommandType = CommandType.Text
        cmd.Connection = con
       
        Dim ImageName As New SqlParameter
                  ("@ImageName", SqlDbType.VarChar, 50)
        ImageName.Value = strImageName.ToString()
        cmd.Parameters.Add(ImageName)
       
        Dim UploadedImage__2 As New SqlParameter
            ("@Image", SqlDbType.Image, imageSize.Length)
        UploadedImage__2.Value = imageSize
        cmd.Parameters.Add(UploadedImage__2)
        con.Open()
        Dim result As Integer = cmd.ExecuteNonQuery()
        con.Close()
        If result > 0 Then
            lblMessage.Text = "File Uploaded"
        End If
        GridView1.DataBind()
    End If
End Sub

HostForLIFE.eu SQL Server 2016 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.



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