Enterprise Library- Data Block使用oracle儲存過程出現問題的解決
[轉]
說明: 執行當前 Web 請求期間,出現未處理的異常。請檢查堆疊跟蹤資訊,以瞭解有關該錯誤以及程式碼中導致錯誤的出處的詳細資訊。
異常詳細資訊: System.Exception: Parameter ''''p_R_URL'''': No size set for variable length data type: String.
源錯誤:
行 67: catch(Exception ex) 行 68: { 行 69: throw new Exception(ex.Message); 行 70: //return false; 行 71: } |
原始檔: c:inetpubwwwrootresourcedatalaydbresource.cs 行: 69
堆疊跟蹤:
[Exception: Parameter ''''p_R_URL'''': No size set for variable length data type: String.] ReSource.DataLay.DbResource.Insert(String R_TITLE, String R_USE, String R_XKML, String R_GRLB, String R_WJLB, DateTime R_ADDTIME, String R_URL, String R_PRIVATE, String R_COMMONT) in c:inetpubwwwrootresourcedatalaydbresource.cs:69 ReSource.BusLay.BusResource.Insert() in c:inetpubwwwrootresourcebuslaybusresource.cs:119 ReSource.WebLay.MYRESOURCEAdd.Insert(Object sender, EventArgs e) in c:inetpubwwwrootresourceweblaytjzymyresourceadd.aspx.cs:80 System.EventHandler.Invoke(Object sender, EventArgs e) +0 System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +108 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138 System.Web.UI.Page.ProcessRequestMain() +1292 |
版本資訊: Microsoft .NET Framework 版本:1.1.4322.2300; ASP.NET 版本:1.1.4322.2300
很是鬱悶,於是就開啟Enterprise Library的原始碼進行除錯。發現問題原來出現在 OracleCommandWrapper.cs檔案中的 如下函式:(從345 行開始)
private OracleParameter CreateParameter(string name, DbType dbType, int size, ParameterDirection direction, bool nullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value)
{
OracleParameter param = this.command.CreateParameter();
param.ParameterName = name;
param.DbType = dbType;
param.Size = size;
param.Value = (value == null) ? DBNull.Value : value;
// modify parameter type and value for special cases
switch (dbType)
{
// for Guid, change to value to byte array
case DbType.Guid:
guidParameters.Add(param.ParameterName, "System.Guid");
param.OracleType = OracleType.Raw;
param.Size = 16;
// convert Guid value to byte array only if not null
if ((value is DBNull) || (value == null))
{
param.Value = Convert.DBNull;
}
else
{
param.Value = ((Guid)value).ToByteArray();
}
break;
// case DbType.AnsiString:
// case DbType.AnsiStringFixedLength:
// case DbType.String:
// case DbType.StringFixedLength:
// // for empty string, set it to DBNull
// if ((value == null) || (!(value is DBNull)) && ((string)value).Length == 0)
// {
// param.Value = Convert.DBNull;
// }
// break;
default:
break;
}
param.Direction = direction;
param.IsNullable = nullable;
param.Precision = precision;
param.Scale = scale;
param.SourceColumn = sourceColumn;
param.SourceVersion = sourceVersion;
return param;
}
{
OracleParameter param = this.command.CreateParameter();
param.ParameterName = name;
param.DbType = dbType;
param.Size = size;
param.Value = (value == null) ? DBNull.Value : value;
// modify parameter type and value for special cases
switch (dbType)
{
// for Guid, change to value to byte array
case DbType.Guid:
guidParameters.Add(param.ParameterName, "System.Guid");
param.OracleType = OracleType.Raw;
param.Size = 16;
// convert Guid value to byte array only if not null
if ((value is DBNull) || (value == null))
{
param.Value = Convert.DBNull;
}
else
{
param.Value = ((Guid)value).ToByteArray();
}
break;
// case DbType.AnsiString:
// case DbType.AnsiStringFixedLength:
// case DbType.String:
// case DbType.StringFixedLength:
// // for empty string, set it to DBNull
// if ((value == null) || (!(value is DBNull)) && ((string)value).Length == 0)
// {
// param.Value = Convert.DBNull;
// }
// break;
default:
break;
}
param.Direction = direction;
param.IsNullable = nullable;
param.Precision = precision;
param.Scale = scale;
param.SourceColumn = sourceColumn;
param.SourceVersion = sourceVersion;
return param;
}
可以看到,程式碼中處理了傳入值為 NULL的情況。但是不知道為什麼把處理字串引數等於 "" 的時候得語句給註釋掉了。於是乎,就更改原始碼,如下:
private OracleParameter CreateParameter(string name, DbType dbType, int size, ParameterDirection direction, bool nullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value)
{
OracleParameter param = this.command.CreateParameter();
param.ParameterName = name;
param.DbType = dbType;
param.Size = size;
param.Value = (value == null) ? DBNull.Value : value;
// modify parameter type and value for special cases
switch (dbType)
{
// for Guid, change to value to byte array
case DbType.Guid:
guidParameters.Add(param.ParameterName, "System.Guid");
param.OracleType = OracleType.Raw;
param.Size = 16;
// convert Guid value to byte array only if not null
if ((value is DBNull) || (value == null))
{
param.Value = Convert.DBNull;
}
else
{
param.Value = ((Guid)value).ToByteArray();
}
break;
case DbType.AnsiString:
case DbType.AnsiStringFixedLength:
case DbType.String:
case DbType.StringFixedLength:
// for empty string, set it to DBNull
if ((value == null) || (!(value is DBNull)) && ((string)value).Length == 0)
{
param.Value = Convert.DBNull;
}
break;
default:
break;
}
param.Direction = direction;
param.IsNullable = nullable;
param.Precision = precision;
param.Scale = scale;
param.SourceColumn =
{
OracleParameter param = this.command.CreateParameter();
param.ParameterName = name;
param.DbType = dbType;
param.Size = size;
param.Value = (value == null) ? DBNull.Value : value;
// modify parameter type and value for special cases
switch (dbType)
{
// for Guid, change to value to byte array
case DbType.Guid:
guidParameters.Add(param.ParameterName, "System.Guid");
param.OracleType = OracleType.Raw;
param.Size = 16;
// convert Guid value to byte array only if not null
if ((value is DBNull) || (value == null))
{
param.Value = Convert.DBNull;
}
else
{
param.Value = ((Guid)value).ToByteArray();
}
break;
case DbType.AnsiString:
case DbType.AnsiStringFixedLength:
case DbType.String:
case DbType.StringFixedLength:
// for empty string, set it to DBNull
if ((value == null) || (!(value is DBNull)) && ((string)value).Length == 0)
{
param.Value = Convert.DBNull;
}
break;
default:
break;
}
param.Direction = direction;
param.IsNullable = nullable;
param.Precision = precision;
param.Scale = scale;
param.SourceColumn =
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-157124/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle儲存過程!解決網友問題Oracle儲存過程
- Java呼叫Oracle儲存過程的問題JavaOracle儲存過程
- 解決儲存過程擷取錯誤的問題儲存過程
- 儲存過程問題。。儲存過程
- Hibernate呼叫oracle儲存過程的問題Oracle儲存過程
- ETL通用解決方案---oracle+儲存過程 實現Oracle儲存過程
- ORACLE中儲存過程的許可權問題Oracle儲存過程
- Oracle儲存過程編譯卡死的解決方法Oracle儲存過程編譯
- Oracle 編譯儲存過程卡死解決方法Oracle編譯儲存過程
- Data Pump Import速度問題之解決過程Import
- 一個儲存過程的問題!儲存過程
- 解決執行儲存過程出現許可權不足問題(ORA-01031)儲存過程
- oracle的儲存過程Oracle儲存過程
- 儲存過程訪問其他使用者的表的問題儲存過程
- oracle 儲存過程遊標的使用Oracle儲存過程
- mysql多次呼叫儲存過程的問題MySql儲存過程
- Oracle 11g Data Guard搭建過程中問題解決兩例Oracle
- 從sybase的儲存過程轉向oracle的儲存過程儲存過程Oracle
- Oracle儲存過程Oracle儲存過程
- oracle父儲存過程呼叫子儲存過程procedure與輸出引數Oracle儲存過程
- oracle儲存過程編譯死掉的原因及解決(zt)Oracle儲存過程編譯
- MySQL儲存過程詳解 mysql 儲存過程MySql儲存過程
- 關於儲存過程中不能操作其他使用者表資料的問題解決儲存過程
- 儲存過程單引號問題儲存過程
- oracle的儲存過程格式Oracle儲存過程
- 使用儲存過程儲存過程
- MySQL儲存過程的許可權問題MySql儲存過程
- Oracle儲存過程乾貨(一):儲存過程基礎Oracle儲存過程
- Oracle儲存過程-1Oracle儲存過程
- Oracle儲存過程例子Oracle儲存過程
- Oracle建立儲存過程Oracle儲存過程
- oracle plsql儲存過程OracleSQL儲存過程
- ORACLE 儲存過程示例Oracle儲存過程
- 儲存過程的詳解儲存過程
- 如何在Oracle中使用Java儲存過程(詳解)(轉)OracleJava儲存過程
- 【實戰】oracle job + 儲存過程 的使用示例Oracle儲存過程
- 達夢儲存過程效能問題定位儲存過程
- Mysql 儲存過程的使用MySql儲存過程