1.在.ashx中向存储过程传输数据,获取执行结果:
SqlConnection conn2 = new SqlConnection(连接数据库); SqlCommand scmd = new SqlCommand(); scmd.Connection = conn2; scmd.CommandText = "存储过程名"; scmd.CommandType = CommandType.StoredProcedure; scmd.Parameters.Clear(); scmd.Parameters.Add("@LS_Parent_Id", SqlDbType.VarChar, 50); scmd.Parameters["@LS_Parent_Id"].Value = LS_Parent_Id; scmd.Parameters["@LS_Parent_Id"].Direction = ParameterDirection.Input; scmd.Parameters.Add("@subject", SqlDbType.VarChar, 150); scmd.Parameters["@subject"].Direction = ParameterDirection.Output; scmd.Connection.Open(); scmd.ExecuteReader(); scmd.Connection.Close(); string subject = scmd.Parameters["@subject"].Value.ToString().Trim();
3.查询利用sql存储过程发送邮件的相关记录:
use msdb go select * from sysmail_allitems select * from sysmail_mailitems select * from sysmail_event_log select * FROM dbo.sysmail_profile
4.利用 SQL Server Database Mail 功能发送邮件:
EXEC msdb.dbo.sp_send_dbmail @profile_name = N'smtp', /** 发送邮件的配置文件名称 **/ @recipients = @recipients, /** 邮件接收者email地址 **/ @copy_recipients = @copy_recipients, /** 抄送给email地址 **/ @subject = @Subject, /** 邮件标题 **/ @body = @tableHTML, /** 邮件内容 **/ @body_format = 'HTML' ; /** 邮件格式 **/
游标一般格式:
DECLARE 游标名称 CURSOR FOR SELECT 字段1,字段2,字段3,... FROM 表名 WHERE ...
OPEN 游标名称
FETCH NEXT FROM 游标名称 INTO 变量名1,变量名2,变量名3,...
WHILE @@FETCH_STATUS=0
BEGIN
SQL语句执行过程... ...
FETCH NEXT FROM 游标名称 INTO 变量名1,变量名2,变量名3,...
END
CLOSE 游标名称
DEALLOCATE 游标名称 (删除游标)