總之,我有一個CLR方法用於從SQL Server向用戶發送電子郵件。我在我的SQL Server表中擁有關於正文,附件,主題,電子郵件等的所有數據信息。那麼,我正在C#中做一個應用程序來做到這一點,我沒有用表格中存儲過程保存信息的麻煩,但是當我想執行我的SP發送ID(郵件)時。這說'命令成功完成',但郵件不發送。然後我測試從SQL Server手動執行我的SP,並正確發送一些ID,有些不'監視'我的發送方法,因爲這樣可以正確執行命令,但是執行任何操作。爲什麼發生這種情況?有人有此問題之前?爲什麼我的存儲過程沒有用某個id執行CLR方法?
這是我的CLR方法
[SqlProcedure]
public static int CustomMethod(int id_email, out string sError)
{
int mReturn = 0;
DataSet ds = new DataSet();
sError = string.Empty;
Dictionary<int, string> ListFile = new Dictionary<int, string>();
try
{
ds = retornarQuery(strQuery: "ZeusFW_Email_List " + id_email);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
DataRow row = ds.Tables[0].Rows[i];
string ds_to_name = (string)row["ds_to_name"];
string ds_to_email = (string)row["ds_to_email"];
string ds_cc_email = (string)row["ds_cc_email"];
string ds_bcc_email = (string)row["ds_bcc_email"];
string ds_idiom = (string)row["ds_idiom"];
string ds_subject = (string)row["ds_subject"];
string ds_body = (string)row["ds_body"];
int am_sent_times = (int)row["am_sent_times"];
int in_process = (int)row["in_process"];
int am_email_port = (int)row["am_email_port"];
string ds_email_host = (string)row["ds_email_host"];
string ds_email_user = (string)row["ds_email_user"];
string ds_email_password = (string)row["ds_email_password"];
int am_email_html = (int)row["am_email_html"];
int am_email_ssl = (int)row["am_email_ssl"];
string ds_email_name = (string)row["ds_email_name"];
string ds_email_xsl = (string)row["ds_email_xsl"];
int in_email_log = (int)row["in_email_log"];
DeliveryNotificationOptions am_notificationoptions = NotificationOptions((int)row["am_notificationoptions"]);
MailPriority am_priority = Priority((int)row["am_priority"]);
if (in_process == 0 && am_email_html == 1)
{
ds_body = DoXSLT(ds_body, ds_email_xsl);
}
ZeusFrameworkSmtp.ZeusFrameworkSmtp email = new ZeusFrameworkSmtp.ZeusFrameworkSmtp();
email.AddFrom = ds_email_user;
email.AddName = ds_email_name;
email.AddTo.Add(ds_to_email);
if (ds_cc_email != null || !ds_cc_email.Equals("")) email.AddCC = ds_cc_email;
if (ds_bcc_email != null || !ds_bcc_email.Equals("")) email.AddBcc = ds_bcc_email;
if (am_sent_times > 0) { ds_subject = "Re#" + am_sent_times + " " + ds_subject; }
email.Subject = ds_subject;
email.Body = ds_body;
email.BodyHtml = (am_email_html == 0 ? false : true);
email.Server = ds_email_host;
email.Port = am_email_port;
email.User = ds_email_user;
email.Password = ds_email_password;
email.EnableSsl = (am_email_ssl == 0 ? false : true); ;
email.NotificationOptions = am_notificationoptions;
email.Priority = am_priority;
am_sent_times = am_sent_times + 1;
if (ds.Tables[1].Rows.Count > 0)
{
for (int j = 0; j <= ds.Tables[1].Rows.Count - 1; j++)
{
DataRow rowAttachments = ds.Tables[1].Rows[j];
if (id_email == (int)rowAttachments["id_email"])
{
if ((int)rowAttachments["in_delete_file"] == 1) ListFile.Add(j, (string)rowAttachments["ds_full_path"]);
email.AddAttachments.Add((string)rowAttachments["ds_full_path"]);
}
}
}
bool bresult = email.Send(out sError);
//if (bresult) { mReturn = 1; Database.ZeusFW_Email_Update(id_email, am_sent_times, sError, in_email_log).Run(); }
if (string.IsNullOrEmpty(sError) || sError.Equals("ESTOY EJECUTANDO EL METODO")) sError = "Operación completada con éxito.";
if (ListFile.Count > 0)
{
foreach (KeyValuePair<int, string> item in ListFile)
{
if (item.Key == 1) File.Delete(item.Value.ToString());
}
ListFile.Clear();
}
}
}
else sError = "No se encontró el ID";
}
catch (Exception ex)
{
StringBuilder s = new StringBuilder();
//sError = sError + "-" + "Error executing SQL statement information: " + ex.Message + "id_email : " + id_email.ToString() + "Conn : " + Database.ConnectionString + ex.StackTrace.ToString();
LogWindows _LogWindows = new LogWindows();
_LogWindows.Save("Zeus", sError, System.Diagnostics.EventLogEntryType.Error);
//SqlContext.Pipe.Send("Error executing SQL statement information: " + ex.Message + "id_email> " + id_email_aux.ToString() + "Conn>" + Database.ConnectionString);
}
return mReturn;
}
這是我的存儲過程
CREATE PROCEDURE [dbo].[CustomMethod]
@id_email int
,@sError nvarchar(2000)=NULL OUTPUT
WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [AssemblyNamespace].[AssemblyNamespace.AssemblyNamespace1].[CustomMethod]
GO
這兩個ID在我的SQL表中存在類似的有效郵件。忽略SP的名稱是私有化,他們在CLR方法和存儲過程中有相同的名稱
我在SQL Server中有這個異常。
男裝6522,NIVEL 16,埃斯塔1,Procedimiento ZeusFW_EmailqueueUnit_SendOutError,拉利內阿用戶定義例程或聚合 「ZeusFW_EmailqueueUnit_SendOutError」 的執行過程中出現2
一個.NET Framework錯誤:System.IO.IOException :El sistema no puede ponerse en contacto con un controlador de dominio para que atienda la solicitud deautenticación。 Inténtelode nuevomástarde。
System.IO.IOException:
EN System.IO .__ Error.WinIOError(的Int32的errorCode,字符串maybeFullPath)
EN System.IO.FileStream.Init(字符串路徑,模式的FileMode,FileAccess的訪問,的Int32權利,布爾useRights,FileShare共享,Int32 bufferSize,FileOptions選項,SECURITY_ATTRIBUTES secAttrs,字符串msgPath,布爾bFromProxy)
System.IO.FileStream..ctor(字符串路徑,FileMode模式,FileAccess訪問,FileShare共享,Int32 bufferSize,FileOptions選項,String msgPath,Boolean bFromProxy)
System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share)
烯System.Net.Mail.AttachmentBase.SetContentFromFile(字符串文件名,字符串mediaType的)
烯System.Net.Mail.Attachment..ctor(字符串文件名)
烯ZeusFrameworkSmtp.ZeusFrameworkSmtp.Send(字符串&誤差)
恩AssemblyZeusSMTP.AssemblyZeusSMTP.ZeusFW_EmailqueueUnit_SendOutError(SqlInt32 id_email,的SqlString & sError)
我們可以看看你的代碼,如果你發佈它。 –
我有錯誤。當我從我的應用程序中使用CLR時,會拋出異常System.IO.Exception:系統無法聯繫域控制器來處理身份驗證請求。稍後嘗試Somones知道爲什麼會發生?當我從sql服務器手動插入一行並執行我的sp時,發送正確 –