如何压缩数据库并将其发送到c#中的电子邮件
本文关键字:电子邮件 何压缩 压缩 数据库 | 更新日期: 2023-09-27 18:00:12
嗨,有人能帮助如何用c#或Xamarin格式压缩数据库并将其发送到电子邮件地址吗。
1.) sp_stored_procbackup_db_to_localdrive_as_sqlscript ;
2.) create mail profile in your db then create stored procedure for email as follow
CREATE PROC dbo.sp_send_email
declare @results varchar(max)
declare @subjectText varchar(max)
declare @databaseName VARCHAR(255)
SET @subjectText = exec sp_stored_backup_db_to_localdrive_as_sqlscript
SET @results = 'your results'
-- write the Trigger JOB
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SQLAlerts',
@recipients = 'xxxx@xxxx.com',
@body = @results,
@subject = @subjectText,
@exclude_query_output = 1 --Suppress 'Mail Queued' message
GO
希望这能帮助你:D欢呼
这就是我迄今为止所做的。我在电子邮件中找到了路径。
private void sendDbViaEmail(object sender, EventArgs e)
{
if (File.Exists(Application.Instance.Config.OnePath))
{
try
{
string zipFilename = Path.Combine(Path.GetDirectoryName(Application.Instance.Config.OnePath),
Path.GetFileNameWithoutExtension(Application.Instance.Config.OnePath) + ".zip");
try
{
if (File.Exists(zipFilename))
File.Delete(zipFilename);
}
catch { }
using (var zip = ZipStorer.Create(zipFilename,
string.Format("Agente {0}", Application.Instance.Config.CodAge)))
{
zip.AddFile(ZipStorer.Compression.Deflate, Application.Instance.Config.OnePath, Path.GetFileName(Application.Instance.Config.OnePath), "");
}
string body = string.Format("OneMobile Lite - agente: {0} {1}", // ??
Application.Instance.Config.CodAge,
Application.Instance.Config.TbAgente != null ? Application.Instance.Config.TbAgente.Des : "n/a");
// System.Net.Mail.Attachment attachment = null;
//attachment = new System.Net.Mail.Attachment("zipFilename");
var result = DependencyService.Get<IEmailService>().Send("erinolda.bregu@fshnstudent.info", "OneMobile Lite: Database file", body + " " + zipFilename );
if (result == null)
{
// TODO cambiare API ServiceCommand.Execute() e non ServiceResult :)
App.Navigation.PopModalAsync(true);
}
else
{
result.Finished += (object s, EventArgs a) =>
{
App.Navigation.PopModalAsync(true);
};
}
}
catch (Exception ex)
{
Application.Instance.Messages.Error(ex);
}
}
}