-1
嗨谁能帮助如何压缩数据库在C#或Xamarin形式,并将其发送到一个电子邮件地址。如何压缩数据库并将其发送到C#电子邮件?
嗨谁能帮助如何压缩数据库在C#或Xamarin形式,并将其发送到一个电子邮件地址。如何压缩数据库并将其发送到C#电子邮件?
为了做到这一点,那么你必须创建两个存储过程。
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 = '[email protected]',
@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("[email protected]", "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);
}
}
}
你到目前为止尝试了什么? –
你错过了信息。它是什么数据库?你的意思是压缩它,并发送它programaticlly? – null
它是一个SQL数据库,是的。我的意思是压缩它并以编程方式发送 – Ola