CreateParameter give bad performance

We are working with MSSQL 2005 and ado.net framework 1.1

During our performance tests over large DB (~1M records) I found out that when I run one of our queries, with embeded values in the query-string, instead of using the CreateParametr method, the query ran 40 times faster!!!

The parameters are 2 strings (~30 characters), the type in database is varchar(255).

What can cause such a huge difference in the execution time

This is our AddParameter source:

public void AddParameter(object parameterValue)

{

string paramName;

IDataParameter IParam;

//For string that is empty do nothing means null is entered to field.

if(((parameterValue is string) && (parameterValue.ToString()==String.Empty))

|| (parameterValue==null) || (parameterValue is DBNull))

return;

IParam = m_command.CreateParameter();

IParam.Value = parameterValue;

if(m_paramMark.Length > 1)

{

paramName = m_paramMark + m_paramCount.ToString();

IParam.ParameterName= paramName;

m_paramCount++;

}

m_command.Parameters.Add(IParam);

}

We are using the Interface IDataParameter and not SqlParameter because our code is generic.

Thanks,

Dalila



Answer this question

CreateParameter give bad performance