微软企业库中数据库访问代码问题(System.InvalidOperationException: Parameter '@FileContent' exceeds the size limit fo...

System.InvalidOperationException: Parameter '@FileContent' exceeds the size limit for the sql_variant datatype.

以前采用for .net 1.1时没有问题

现在采用for .net 2.0版本时出现

数据访问代码如下:

 1 None.gif   public   bool  Create(Guid FileID,  string  ParentType, Guid ParentID,  string  FileName, Int32 FileSize,  string  MimeType, DateTime InputDateTime,  string  FileDescription,  byte [] FileContent)
 2 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 3InBlock.gif            Database db = DatabaseFactory.CreateDatabase("STM");
 4InBlock.gif            string sqlCommand = "Files_Create";
 5InBlock.gif            DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
 6InBlock.gif            db.AddReturnValueParameter(dbCommand);
 7InBlock.gif            db.AddInParameter(dbCommand, "@FileID", DbType.Guid, FileID);
 8InBlock.gif            db.AddInParameter(dbCommand, "@ParentType", DbType.String, ParentType);
 9InBlock.gif            db.AddInParameter(dbCommand, "@ParentID", DbType.Guid, ParentID);
10InBlock.gif            db.AddInParameter(dbCommand, "@FileName", DbType.String, FileName);
11InBlock.gif            db.AddInParameter(dbCommand, "@FileSize", DbType.Int32, FileSize);
12InBlock.gif            db.AddInParameter(dbCommand, "@MimeType", DbType.String, MimeType);
13InBlock.gif            db.AddInParameter(dbCommand, "@InputDateTime", DbType.DateTime, InputDateTime);
14InBlock.gif            db.AddInParameter(dbCommand, "@FileDescription", DbType.String, FileDescription);
15InBlock.gif            db.AddInParameter(dbCommand, "@FileContent", DbType.Object, FileContent);    
16InBlock.gif            db.ExecuteNonQuery(dbCommand);
17InBlock.gif            return 0 == (int)db.GetParameterValue(dbCommand, "@Return_Value");
18ExpandedBlockEnd.gif        }


问题已经定位到采用系统DbCommond时SQL参数没有Image类型导致

是企业库的开发者没有注意到呢?还是我使用不正确呢?

Bolik目前正在尝试解决该问题,等问题解决之后给出解决办法

问题已经解决 代码如下:

 1 None.gif   public   bool  Create(Guid FileID,  string  ParentType, Guid ParentID,  string  FileName, Int32 FileSize,  string  MimeType, DateTime InputDateTime,  string  FileDescription,  byte [] FileContent)
 2 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 3InBlock.gif            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase("STM");
 4InBlock.gif            string sqlCommand = "Files_Create";
 5InBlock.gif            DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
 6InBlock.gif            db.AddReturnValueParameter(dbCommand);
 7InBlock.gif            db.AddInParameter(dbCommand, "@FileID", DbType.Guid, FileID);
 8InBlock.gif            db.AddInParameter(dbCommand, "@ParentType", DbType.String, ParentType);
 9InBlock.gif            db.AddInParameter(dbCommand, "@ParentID", DbType.Guid, ParentID);
10InBlock.gif            db.AddInParameter(dbCommand, "@FileName", DbType.String, FileName);
11InBlock.gif            db.AddInParameter(dbCommand, "@FileSize", DbType.Int32, FileSize);
12InBlock.gif            db.AddInParameter(dbCommand, "@MimeType", DbType.String, MimeType);
13InBlock.gif            db.AddInParameter(dbCommand, "@InputDateTime", DbType.DateTime, InputDateTime);
14InBlock.gif            db.AddInParameter(dbCommand, "@FileDescription", DbType.String, FileDescription);
15InBlock.gif            db.AddInParameter(dbCommand, "@FileContent", SqlDbType.Image, FileContent);    
16InBlock.gif            db.ExecuteNonQuery(dbCommand);
17InBlock.gif            return 0 == (int)db.GetParameterValue(dbCommand, "@Return_Value");
18ExpandedBlockEnd.gif        }

请注意两段代码中的第3行与第15行中的强制转换,之所以转换是因为DbCommand不支持Image类型,但这样就要求在数据库连接字符串中强制使用SQL Server了,不知道有没有更好的解决方法

转载于:https://www.cnblogs.com/Bolik/archive/2006/04/10/371422.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值