我的应用程序的一些背景。
我正在使用C#开发File Watcher Windows 服务,该服务在特定文件夹中查找.bak文件,然后使用它来恢复该文件所属的数据库。
恢复的数据库有一个存储过程,它调用 10 个不同的存储过程。在还原完成后执行存储过程是文件观察器的功能。
存储过程是[1_IMPORT_DATA_AND_PROCESS_ALL]在其自身内部调用 10 个不同的存储过程。
这是还原完成后正在执行存储过程的方法。
// Trigger Stored Procedure after restore.
private void triggerSP(String connectionStr)
{
// This doesn't open the Connection. conn.Open() has to be explicitly called.
SqlConnection conn = new SqlConnection(connectionStr);
try
{
conn.Open();
conn.FireInfoMessageEventOnUserErrors = true;
// Capture messages returned by SQL Server.
conn.InfoMessage += delegate (object sender, SqlInfoMessageEventArgs e)
{
message += " -> " + e.Message + " -> ";
};
//conn.InfoMessage += new SqlInfoMessageEventHandler(cn_InfoMessage);
//.create a command object identifying the stored procedure.
SqlCommand cmd = new SqlCommand("[dbo].[1_IMPORT_DATA_AND_PROCESS_ALL]", conn);
cmd.CommandTimeout = 0;
// 2. set the command object so it knows to execute a stored procedure.
cmd.CommandType = CommandType.StoredProcedure;
// Add a check here as well.
// execute the command.
SqlDataReader rdr = cmd.ExecuteReader();
string[] info = new string[] { "Message: \n" + message };
WriteToFile(info);
// Since we are not using - using block we have to explicitly call Close() to close the connection.
conn.Close();
}
catch (SqlException SqlEx){
string[] error = new string[3] ;
string msg1 = "Errors Count:" + SqlEx.Errors.Count;
string msg2 = null;
foreach (SqlError myError in SqlEx.Errors)
msg2 += myError.Number + " - " + myError.Message + "/" ;
conn.InfoMessage += delegate (object sender, SqlInfoMessageEventArgs e)
{
message += "\n" + e.Message;
};
error[0] = msg1;
error[1] = msg2;
error[2] = message;
WriteToFile(error);
}
问题
我只是从第一个存储过程中取回消息输出,而不是从如下所示[1_IMPORT_DATA_AND_PROCESS_ALL]的从内部调用的存储过程中取回消息输出。[1_IMPORT_DATA_AND_PROCESS_ALL]
慕丝7291255
相关分类