System.InvalidOperationException: Parameter '@FileContent' exceeds the size limit for the sql_variant datatype.
以前采用for .net 1.1时没有问题
现在采用for .net 2.0版本时出现
数据访问代码如下:
1 public bool Create(Guid FileID, string ParentType, Guid ParentID, string FileName, Int32 FileSize, string MimeType, DateTime InputDateTime, string FileDescription, byte[] FileContent)
2 {
3 Database db = DatabaseFactory.CreateDatabase("STM");
4 string sqlCommand = "Files_Create";
5 DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
6 db.AddReturnValueParameter(dbCommand);
7 db.AddInParameter(dbCommand, "@FileID", DbType.Guid, FileID);
8 db.AddInParameter(dbCommand, "@ParentType", DbType.String, ParentType);
9 db.AddInParameter(dbCommand, "@ParentID", DbType.Guid, ParentID);
10 db.AddInParameter(dbCommand, "@FileName", DbType.String, FileName);
11 db.AddInParameter(dbCommand, "@FileSize", DbType.Int32, FileSize);
12 db.AddInParameter(dbCommand, "@MimeType", DbType.String, MimeType);
13 db.AddInParameter(dbCommand, "@InputDateTime", DbType.DateTime, InputDateTime);
14 db.AddInParameter(dbCommand, "@FileDescription", DbType.String, FileDescription);
15 db.AddInParameter(dbCommand, "@FileContent", DbType.Object, FileContent);
16 db.ExecuteNonQuery(dbCommand);
17 return 0 == (int)db.GetParameterValue(dbCommand, "@Return_Value");
18 }
2 {
3 Database db = DatabaseFactory.CreateDatabase("STM");
4 string sqlCommand = "Files_Create";
5 DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
6 db.AddReturnValueParameter(dbCommand);
7 db.AddInParameter(dbCommand, "@FileID", DbType.Guid, FileID);
8 db.AddInParameter(dbCommand, "@ParentType", DbType.String, ParentType);
9 db.AddInParameter(dbCommand, "@ParentID", DbType.Guid, ParentID);
10 db.AddInParameter(dbCommand, "@FileName", DbType.String, FileName);
11 db.AddInParameter(dbCommand, "@FileSize", DbType.Int32, FileSize);
12 db.AddInParameter(dbCommand, "@MimeType", DbType.String, MimeType);
13 db.AddInParameter(dbCommand, "@InputDateTime", DbType.DateTime, InputDateTime);
14 db.AddInParameter(dbCommand, "@FileDescription", DbType.String, FileDescription);
15 db.AddInParameter(dbCommand, "@FileContent", DbType.Object, FileContent);
16 db.ExecuteNonQuery(dbCommand);
17 return 0 == (int)db.GetParameterValue(dbCommand, "@Return_Value");
18 }
问题已经定位到采用系统DbCommond时SQL参数没有Image类型导致
是企业库的开发者没有注意到呢?还是我使用不正确呢?
Bolik目前正在尝试解决该问题,等问题解决之后给出解决办法
问题已经解决 代码如下:
1 public bool Create(Guid FileID, string ParentType, Guid ParentID, string FileName, Int32 FileSize, string MimeType, DateTime InputDateTime, string FileDescription, byte[] FileContent)
2 {
3 SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase("STM");
4 string sqlCommand = "Files_Create";
5 DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
6 db.AddReturnValueParameter(dbCommand);
7 db.AddInParameter(dbCommand, "@FileID", DbType.Guid, FileID);
8 db.AddInParameter(dbCommand, "@ParentType", DbType.String, ParentType);
9 db.AddInParameter(dbCommand, "@ParentID", DbType.Guid, ParentID);
10 db.AddInParameter(dbCommand, "@FileName", DbType.String, FileName);
11 db.AddInParameter(dbCommand, "@FileSize", DbType.Int32, FileSize);
12 db.AddInParameter(dbCommand, "@MimeType", DbType.String, MimeType);
13 db.AddInParameter(dbCommand, "@InputDateTime", DbType.DateTime, InputDateTime);
14 db.AddInParameter(dbCommand, "@FileDescription", DbType.String, FileDescription);
15 db.AddInParameter(dbCommand, "@FileContent", SqlDbType.Image, FileContent);
16 db.ExecuteNonQuery(dbCommand);
17 return 0 == (int)db.GetParameterValue(dbCommand, "@Return_Value");
18 }
2 {
3 SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase("STM");
4 string sqlCommand = "Files_Create";
5 DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
6 db.AddReturnValueParameter(dbCommand);
7 db.AddInParameter(dbCommand, "@FileID", DbType.Guid, FileID);
8 db.AddInParameter(dbCommand, "@ParentType", DbType.String, ParentType);
9 db.AddInParameter(dbCommand, "@ParentID", DbType.Guid, ParentID);
10 db.AddInParameter(dbCommand, "@FileName", DbType.String, FileName);
11 db.AddInParameter(dbCommand, "@FileSize", DbType.Int32, FileSize);
12 db.AddInParameter(dbCommand, "@MimeType", DbType.String, MimeType);
13 db.AddInParameter(dbCommand, "@InputDateTime", DbType.DateTime, InputDateTime);
14 db.AddInParameter(dbCommand, "@FileDescription", DbType.String, FileDescription);
15 db.AddInParameter(dbCommand, "@FileContent", SqlDbType.Image, FileContent);
16 db.ExecuteNonQuery(dbCommand);
17 return 0 == (int)db.GetParameterValue(dbCommand, "@Return_Value");
18 }
请注意两段代码中的第3行与第15行中的强制转换,之所以转换是因为DbCommand不支持Image类型,但这样就要求在数据库连接字符串中强制使用SQL Server了,不知道有没有更好的解决方法