I could use some help dealing with null blobs. I'm
returning a transaction from an Image BLOB field in SQL
Server 2000 using C#. If the transaction exists the value
is returned with out trouble, but because the ID can exist
without having a value in the Image column the returned
value is NULL and the code can't handle it and I receive
this error when the Stored Procedure's value is returned
(the line of code is marked with "**HERE**":
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and where
it originated in the code.
Exception Details:
System.Web.Serv ices.Protocols. SoapException:
System.Web.Serv ices.Protocols. SoapException: Server was
unable to process request. --->
System.InvalidC astException: Specified cast is not valid.
at
CareVu.WebServi ces.Transaction Servicesm.Trans actionServices
..GetRejectedTr ansaction(Int32 txnId) in
c:\inetpub\wwwr oot\web\transac tionservices.as mx.cs:line
475 --- End of inner exception stack trace ---
Here is the code in the transactionserv ices.asmx.cs file:
/// <summary>
/// Retrieves an XML representation of a
transaction given its ID
/// </summary>
/// <param name="txnId">Th e transaction
ID</param>
/// <returns>Stri ng (xml)</returns>
[WebMethod]
public string GetRejectedTran saction(int
txnId)
{
SqlConnection conn = new
SqlConnection() ;
try
{
conn.Connection String =
System.Configur ation.Configura tionSettings.Ap pSettings
["ConnectionStri ng"];
SqlParameter[] parms = new
SqlParameter[1];
parms[0] = new SqlParameter
("@txnId", SqlDbType.Int);
parms[0].Value = txnId;
**HERE** byte[] weakBlob = (byte[])
SqlHelper.Execu teScalar(conn,
CommandType.Sto redProcedure, "GetRejectedTra nsaction",
parms);
if (weakBlob != null)
{
System.Text.Str ingBuilder contents = new
System.Text.Str ingBuilder(weak Blob.Length - 1);
for(int i = 0; i <
weakBlob.Length ; i++)
{
contents.Append (System.Convert .ToChar(weakBlo b
[i]));
}
return
contents.ToStri ng();
}
else
{
return "";
}
}
catch(Exception exc)
{
throw exc;
}
finally
{
if (conn.State !=
ConnectionState .Closed)
{
conn.Close();
}
}
}
And here is the Stored Procedure:
CREATE proc dbo.GetRejected Transaction
(
@txnId int
)
as
set nocount on
select
WeakBlob
from Transactions
where ID = @txnId
GO
Any help would be appreciated.
Thanks,
Matt