Sending an email from C# script is quite easy thing. Most popular two ways to send an email from C# scripts are as follows:
1.)
public string sendingMail(string strFrom, string strTo, string strSubject, string strMessage)
{
MailMessage myMessage = new MailMessage(new MailAddress(strFrom), new MailAddress(strTo));
myMessage.IsBodyHtml = true;
myMessage.Priority = MailPriority.Normal;
myMessage.Body = strMessage;
myMessage.Subject = strSubject;
SmtpClient client = new SmtpClient("
try
{
client.Send(myMessage);
}
catch(Exception ex)
{
return ex.ToString();
}
return "Message Has Been Sent";
}
2.)
public string AuthenticatedMailSend(string mailTo, string Subject, string MessageBody)
{
System.Net.Mail.MailMessage email = new MailMessage("TEST@test.com", mailTo);
email.Subject = Subject;
email.IsBodyHtml = true;
email.Body = MessageBody;
System.Net.Mail.SmtpClient mailClient = new SmtpClient();
System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("
mailClient.Host = "
mailClient.Port = 25;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = basicAuthenticationInfo;
try
{
mailClient.Send(email);
}
catch (Exception ex)
{
return ex.ToString();
}
return "1";
}
You ccan use any of the above methods, some mail server only supports authenticated email send by script. In that case, go for 2nd method.
Don’t forget to reference “using System.Net.Mail;” namespace for sending an email.
Email sending script from C#
Friday, May 2, 2008 |
Posted by
Ritesh Shah
0
comments
Labels:
T-sql
Links to this post
SQL Server Truncate Transaction Log script
|
Posted by
Ritesh Shah
Many time, it happens in live sql server which has big transaction log file, you run DBCC SHRINKFILE command and see no effect of it on the transaction log file. You can use following magical five line at that time and you will done. It shrinks the trucated log File to minimum size possible.
-------------------------------------------------------------------------
USE DBName
GO
DBCC SHRINKFILE(transactionlogfilename
BACKUP LOG
DBCC SHRINKFILE(transactionlogfilename
------------------------------------------------------------------------
Happy Working!!!!
6
comments
Labels:
T-sql
Links to this post
COALESCE() function in SQL-Server for getting comma seperated value
Thursday, May 1, 2008 |
Posted by
Ritesh Shah
Microsoft Definition:
This function returns first nonnull expresion among its argument.
You can use this function to get column values in one record set with separator like comma, dash etc. Before invention of this function, people used to achieve this kind of stuff by cursor which is time consuming. So, lets have a look at magical function by Microsoft.
Create following table in your database.
create table Testing( mid int ,name varchar(10) ,[18QI] varchar(10))
After creating the table, insert following records.
insert into Testing VALUES(1,'BC','01')
insert into Testing VALUES(2,'BC','10')
insert into Testing VALUES(3,'BC','02')
insert into Testing VALUES(4,'BC','04')
Now, we are all set to see the new powerful function COALESCE() in SQL-Server. Too see the magic, create following function in your database.
CREATE FUNCTION DBO.Get18QI(@ID char(100))RETURNS VARCHAR(1000)
AS
BEGIN
DECLARE @QIList varchar(1000)
SELECT @QIList = COALESCE(@QIList + ', ', '') + convert(varchar,T.[18QI]) FROM Testing T WHERE T.name = @ID and T.[18QI] is not null
RETURN @QIList
END
after successfully creating the function, here we go to see the cool result by following query.
select DBO.Get18QI('BC') as ComaValues
Hope you people will find this article useful.
Happy Working!!!!
1 comments
Labels:
coalesce,
T-sql
Links to this post
Blog Archive
-
►
2011
(43)
-
►
July
(17)
- Index Fill Factor in SQL Server
- ISNULL, COALESCE or CONCAT_NULL_YIELDS_NULL in SQL...
- Should Auto_Close database property be ON or OFF i...
- Msg 22926, Level 16, State 1, Procedure sp_cdc_ver...
- Change Data Capture (CDC) in SQL Server 2008
- Find your backup history in SQL Server
- FileStream in SQL Server 2008+
- Get your server hardware information via DM_OS_SYS...
- Know your processor by XP_Instance_RegRead SP in S...
- Take mirror backup of database in SQL Server 2005/...
- SP_RefreshSqlModule in SQL Server 2005/2008
- What version to go for (updgrade) after SQL Server...
- Msg 7301 Cannot obtain the required interface ("II...
- OpenRowSet and OpenQuery in SQL Server 2005/2008
- Audit Trail with OUTPUT clause in SQL Server 2005/...
- Find third highest salary from Employee table
- Understand SET STATISTICS IO as a first step for p...
-
►
June
(15)
- Executing Stored Procedure with Result Sets in SQL...
- MERGE statement in SQL Server 2008 and later versi...
- Find missing Index with DMVs in SQL Server 2005/20...
- Find unused index in SQL Server 2005/2008/Denali
- Index Reorganize and Rebuild in SQL Server
- Do you know Index Statistics in SQL Server?
- List of articles about Index in SQLHub.com
- Filtered Index in SQL Server 2008/Denali
- Included Column Index with non clustered index in ...
- Nonclustered Index in SQL Server
- Clustered Index in SQL Server
- Some basics about Index in SQL Server
- Answer BI Quiz and win IPAD
- Tech-Ed 2011 on the Road in Ahmedabad
- Be selective while creating an Index in SQL Server...
-
►
July
(17)
Pages
About Me
- Ritesh Shah
- Ritesh Shah is a data professional with having 10+ years of experience in various domain of IT field. He is a author of many technical articles on Microsoft Technology and authored a book of SQL Server 2012 Performance Tuning.
RSS
Feed
