我想上傳文件到我的數據庫(通過讀取二進制文件內容到我的存儲過程)。我傳遞的輸入流,以我的方法,像這樣:無效的文本,ntext或圖像指針值
LoadFile(gAttachmentContentID, file.InputStream, trn);
public static void LoadFile2(Guid gAttachmentContentID, Stream stm, IDbTransaction trn)
{
stm.Position = 0;
byte[] binFILE_POINTER = new byte[32];
// Now read s into a byte buffer.
byte[] bytes = new byte[stm.Length];
int numBytesToRead = (int)stm.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to 10.
int n = stm.Read(bytes, numBytesRead, 10);
// The end of the file is reached.
if (n == 0)
{
break;
}
numBytesRead += n;
numBytesToRead -= n;
}
stm.Close();
SqlProcs.spATTACHMENTS_CONTENT_WriteOffset(gAttachmentContentID, binFILE_POINTER, 0, bytes, trn);
// numBytesToRead should be 0 now, and numBytesRead should
// equal 100.
Console.WriteLine("number of bytes read: {0:d}", numBytesRead);
}
有了這個過程:
public static void spATTACHMENTS_CONTENT_WriteOffset(Guid gID, byte[] binFILE_POINTER, Int32 nFILE_OFFSET, byte[] byBYTES, IDbTransaction trn)
{
IDbConnection con = trn.Connection;
using (IDbCommand cmd = con.CreateCommand())
{
cmd.Transaction = trn;
cmd.CommandType = CommandType.StoredProcedure;
if (Sql.IsOracle(cmd))
cmd.CommandText = "spATTACHMENTS_CONTENT_WriteOff";
else
cmd.CommandText = "spATTACHMENTS_CONTENT_WriteOffset";
IDbDataParameter parID = Sql.AddParameter(cmd, "@ID" , gID );
IDbDataParameter parFILE_POINTER = Sql.AddParameter(cmd, "@FILE_POINTER" , binFILE_POINTER );
IDbDataParameter parMODIFIED_USER_ID = Sql.AddParameter(cmd, "@MODIFIED_USER_ID", Security.USER_ID );
IDbDataParameter parFILE_OFFSET = Sql.AddParameter(cmd, "@FILE_OFFSET" , nFILE_OFFSET );
IDbDataParameter parBYTES = Sql.AddParameter(cmd, "@BYTES" , byBYTES );
cmd.ExecuteNonQuery();
}
}
,但我得到了以下錯誤:
Invalid text, ntext, or image pointer value 0x00000000000000000000000000000000.
上線時出現錯誤我的存儲過程方法的cmd.ExecuteNonQuery();
。
存儲過程:
Create Procedure dbo.spATTACHMENTS_CONTENT_WriteOffset
(@ID uniqueidentifier
, @FILE_POINTER binary(16)
, @MODIFIED_USER_ID uniqueidentifier
, @FILE_OFFSET int
, @BYTES image
)
with encryption
as
begin
set nocount on
-- 10/22/2005 Paul. @ID is used in Oracle and MySQL.
-- #if SQL_Server /*
updatetext ATTACHMENTS_CONTENT.ATTACHMENT
@FILE_POINTER
@FILE_OFFSET
null -- 0 deletes no data, null deletes all data from insertion point.
@BYTES;
謝謝。
可我們看到的存儲過程的代碼? – 2013-02-20 17:53:50
當然可以,它已被更新。 – user1477388 2013-02-20 17:54:47
你爲什麼只用updatetext更新字段的*部分?爲什麼不更換它? – 2013-02-20 17:58:27