Jitendra Kachhi
Monday, 10 April 2023
Thursday, 4 July 2019
How to check windows service is running or not in c#.
Hi All,
I have created console application to verify the installed service status running or stopped.
Below are code.
1) Add below the keys in your application.
<add key ="ServicesName " value="SCardSvr, SNMPTRAP, Appinfo"></add>
<add key ="ToEmail" value="abc@gmail.com"></add>
<add key ="ProjectName" value="HIP Teva"/>
<add key ="EnvironmentName" value="Test"/>
<add key ="FromEmail" value="abc@gmail.com"/>
<! --Email body in in key-->
<add key="EmailTemplate " value="Hi %ToEmail% , <br><br>Please verify below service on %environmentName% environment . <br> <br> %stoppedServices% Sever IP address : %serverIP% <br><br><br> Thanks"></add>
2) Add
System. ServiceProcess
on your project references from NuGet
3) Add below code.
{
{
var serviceNamelist = serviceNamesCommaseparated.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// To Loop through
{
{
{
}
}
}
{
//Send Emial to the admin and also log in log file
}
}
}
{
// Verify server name is installed or not in server
{
{
}
}
{
}
}
{
{
StreamWriter log ;
{
}
{
}
// Write to the file:
// Close the stream:
}
{
}
}
{
{
MailMessage mm = new MailMessage( );
mm.Body = EmailTemplate.Replace("%ToEmail%", ToEmail).Replace("%environmentName%", environmentName).Replace("%stoppedServices%", stoppedServices).Replace("%serverIP%", serverIP);
foreach (var RecepientEmail in fRecepientEmail.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { mm.To.Add(RecepientEmail); }
}
{
}
}
I have added to all services that need to be verify in web. config file. If services are stopped or postponed then application send the email in provided email.
Thanks for reading.
Monday, 18 March 2019
How to take all database offline at one in SQL Server
Hi All,
Today, we are going to learn how we can take all the Databases offline at one time by using SQL scripts.
Below are the SQL scripts.
DECLARE @dbName SYSNAME
DECLARE cursor_db CURSOR
FOR
SELECT name
FROM sys . databases
WHERE owner_sid <> 0x01;
OPEN cursor_db;
WHILE 1 = 1
BEGIN
FETCH NEXT
FROM cursor_db
INTO @dbName;
IF @@FETCH_STATUS <> 0
BREAK;
SET @query = N'ALTER DATABASE [' + @dbName + N'] SET OFFLINE WITH NO_WAIT';
EXEC (@query);
END;
CLOSE cursor_db;
DEALLOCATE cursor_db;
Thanks for reading.
Wednesday, 15 November 2017
How to create query shortcut in SQL server
Hi All,
Today I am going to explain how to create query shortcut in SQL server.
Go to tools.
Click on Options-> Keyboard -> Query Shortcuts.
In the right site you can see query shortcuts and command. Please enter your query.
Click on save button.
Open new query window (Ctrl+N) and enter your table name.
Select your table name and press Ctrl+3 shortcut.
Thanks for reading :)
How to restore database by using T-SQL Scripts
Hi All,
Today I am going to explain how to restore database by using T-SQL Scripts. We already have database in sql server and database backup file .
DECLARE @DbName nvarchar(50)
SET @DbName = N'TestDB'
DECLARE @EXECSQL varchar(max)
SET @EXECSQL = ''
SELECT @EXECSQL = @EXECSQL + 'Kill ' + Convert(varchar, SPId) + ';'
FROM MASTER..SysProcesses
WHERE DBId = DB_ID(@DbName) AND SPId =@@SPId
EXEC(@EXECSQL)
ALTER DATABASE [TestDB] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE [TestDB] FROM DISK = 'D:\backup\TestDB.bak' WITH REPLACE
GO
Thanks for reading. :)
Friday, 24 March 2017
Data Type in JavaScript
JavaScript has five primitive data type.
1 Number
2 String
3 Boolean
4 Undefined
5 Null
Any data type other than above 5 types is called object.
In javascript there are two types to object.
- Build in object
- Custom object
Build in Object : Examples include array, date etc. In below example we have create the object of date by using date constructor.
var date= new Date();
alert(date.getDate);
alert(date.getFullYear);
Custom objects : In JavaScript we don't have classes. We use function instead of classes.
In JavaScript there are two ways to create a custom object.
1. Constructor function
2. Literal notation
Constructor Function
<script type="text/javascript">
function Student(firstName, lastName)
{
this.firstName = firstName;
this.lastName = lastName;
this.getFullName = function ()
{
return this.firstName + " " + this.lastName;
}
}
var student= new Student("Jitendra", "Kachhi");
document.write("First Name :" + student.firstName + "<br/>");
document.write("Last Name : " + student.lastName + "<br/>");
document.write("Full Name :" + student.getFullName() + "<br/>");
</script>
literal Notation
<script type="text/javascript">
var student=
{
firstName: "Jitendra",
lastName: "Kachhi",
FullName: function ()
{
return this.firstName + " " + this.lastName;
}
}
document.write("FirstName = " + student.firstName + "<br/>");
document.write("LastName = " + student.lastName + "<br/>");
document.write("FullName = " + student.FullName() + "<br/>");
</script>
Note:- literal Notation will have only single object(singleton), if we want to create multiple object use Constructor Function.
Thanks you for reading.
Subscribe to:
Posts (Atom)
-
Hi Guys, you can resolve this issue "Error during serialization or deserialization using the JSON JavaScriptSerializer. The lengt...
-
Hi All, Today i am going to explain the default scope of class in C# . default scope of class is internal , Class can ...
-
Today i am going to explain what is access modifiers in C#. One of the most favorite question of interviewer. What is modifiers? Di...