开发者

T-SQL Raiserror Losses Message If Includes Datetime Converted To Char(10)

Okay, so I am trying to raise an error in T-SQL (SQL-2000). The base Sql code looks like this . . .

declare @TmsString  char(10),
        @TmsLast    datetime,
        @UserMsg    varchar(500)

select @TmsLast = getdate()

select  @TmsString = ltrim(rtrim(convert(char(10), @TmsLast, 101)))
select  @UserMsg = '*' + ltrim(rtrim(cast(@TmsString as char))) + '*'

raiserror (@UserMsg, 12, 1)
return

My Managed C++ Code in VS2008 to catch the raiserror looks like this . . .

System::Void Sql_ExecuteQuery (SqlCommand ^ sqlCommand, DataSet ^ OutDS, String ^ TableName)
{
   SqlConnection   ^ sqlConnect ;
   SqlDataAdapter  ^ sqlDA ;

   try
   {
      sqlDA = gcnew SqlDataAdapter () ;

      sqlConnect = gcnew SqlConnection (_ConnString) ;
      sqlConnect->Open () ;

      sqlCommand->Connection = sqlConnect ;

      sqlDA->SelectCommand = sqlCommand ;
      sqlDA->Fil开发者_运维技巧l (OutDS, TableName) ;
   }
   catch (Exception ^ excp)
   {
      throw gcnew Exception (excp->Message->ToString()) ;
   }
   finally
   {
      sqlConnect->Close () ;
   }
}

Now, I have a breakpoint sest at the catch within the "C++" code. If the raiserror message includes the datetime as a CHAR, the excp->Message is empty. If I remove the datetime as a CHAR and just send a hardcoded raiserror message such as "Error happens here", then the excp->Message is complete and filled in with the raiserror message.

Has anybody else seen this type of activity? What can I do on either side of this call . . . i.e., either on the SQL side or the C++ side to get this datetime string included in the raiserror message????

Please, help. I am stuck!

THANK YOU !


What you are executing is

declare @UserMsg    varchar(500)
select  @UserMsg = '*' + convert(char(10), getdate(), 101) + '*'
raiserror (@UserMsg, 12, 1)
return

I guess you would like to concatinate a user msg somehow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜