EnterpriseLibrary Database.cs exception

Topics: Development Team Discussion, User Discussion
Apr 5, 2012 at 8:14 AM

DoExecuteReader method of Microsoft.Practises.EnterpriseLibrary.Data.Database.cs class is throwing exception

 ""Failed to convert parameter value from a SqlParameter to a String."

Here is the stack trace



   at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType)
   at System.Data.SqlClient.SqlParameter.GetCoercedValue()
   at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
   at System.Data.SqlClient.SqlCommand.SetUpRPCParameters(_SqlRPC rpc, Int32 startCount, Boolean inSchema, SqlParameterCollection parameters)
   at System.Data.SqlClient.SqlCommand.BuildRPC(Boolean inSchema, SqlParameterCollection parameters, _SqlRPC& rpc)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at Microsoft.Practices.EnterpriseLibrary.Data.Database.DoExecuteReader(DbCommand command, CommandBehavior cmdBehavior) in C:\Users\Ajay_Thakur01\Desktop\entlib-90009\Blocks\Data\Src\Data\Database.cs:line 453

Here is the peace of code



public

 

void

GetUserInformation()

{

 

SqlParameter[] arr_objSqlParam = new SqlParameter

[3];

 

IDataReader sdrUserInfo = null

;

 

 

//UserEntity objUser = null;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

int

intUserId = 0;

 

 

string strMailId = null;

 

 

string strUserName = null;

 

 

string strUserRole = null;

 

 

int intCycleOpen = 0;

 

 

bool blnDefaultPassword = false

;

 

 

int

intLocked = 0;

 

 

bool blnNominationId = false

;

 

 

string strSql = "spISFGetUserInformation"

;

arr_objSqlParam[0] =

 

new System.Data.SqlClient.SqlParameter("@txtMailId", DbType

.String);

arr_objSqlParam[0].Value =

 

"abc@gmail.com"

;

arr_objSqlParam[1] =

 

new System.Data.SqlClient.SqlParameter("@txtPassword", DbType

.String);

arr_objSqlParam[1].Value =

 

""

;

arr_objSqlParam[2] =

 

new SqlParameter("@intCycleId", DbType

.Int32);

arr_objSqlParam[2].Value = 13;

Microsoft.Practices.EnterpriseLibrary.Data.

 

Database db = DatabaseFactory.CreateDatabase("MyConnection"

);

 

 

 

// Process results

sdrUserInfo = db.ExecuteReader(

 

"dbo."

+strSql, arr_objSqlParam);

 

 

 

// sdrUserInfo = SqlHelper.ExecuteReader(ISFConn(), CommandType.StoredProcedure, MainDBOwner() & strSql, arr_objSqlParam)

 

 

while

(sdrUserInfo.Read())

{

intUserId = sdrUserInfo.GetInt32(0);

strUserRole = sdrUserInfo.GetString(1);

intCycleOpen = sdrUserInfo.GetInt32(2);

blnDefaultPassword = sdrUserInfo.GetBoolean(3);

intLocked = sdrUserInfo.GetInt32(4);

strUserName = sdrUserInfo.GetString(5);

blnNominationId = sdrUserInfo.GetBoolean(6);

 

}

The innner exception is {"Object must implement IConvertible."}