2016-08-04 8 views
-1

こんにちは、どのようにC#またはXamarin形式でデータベースを圧縮し、電子メールアドレスに送信するよりも助けることができます。データベースを圧縮してC#で電子メールに送信するには?

+5

これまでに何を試みましたか? –

+0

情報が欠落しています。どのデータベースですか?あなたはそれを圧縮し、それをプログラム的に送信することを意味しますか? – null

+0

そのSQLデータベースとはい。私はそれを圧縮し、それをプログラム的に送ることを意味します – Ola

答えて

0

これを行うには、2つのストアドプロシージャを作成する必要があります。あなたを助ける

  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歓声

0

これは私がこれまでにやっていることです。私は自分のメールアドレスにパスを取得します。

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); 
      } 
     } 



    } 
関連する問題