Enterprise Library.DATA - Nov/Dec Preview - Failed to convert parameter value from a SqlParameter to

  • Thread starter Chris Crowe [MVP 1997 -> 2006]
  • Start date
C

Chris Crowe [MVP 1997 -> 2006]

I am having major problems using GetStoredProcCommand and using Parameters
in the same function call in the latest builds of the Enterprise Library
Data.

The error I get is :

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

Here is some code that works and does not work.

// This Works
DbCommand dbCommand1 = new SqlCommand();
dbCommand1.Connection = new
SqlConnection("Server=MyServer;Database=MyDB;uid=MyUID;pwd=MyPassword;");
dbCommand1.CommandType = CommandType.StoredProcedure;
dbCommand1.CommandText = "HTMLGetPageIDFromName";
dbCommand1.Parameters.Add(new SqlParameter("@PageName", PageName));
dbCommand1.Connection.Open();
object value1 = dbCommand1.ExecuteScalar();

// Shared

Database db = DatabaseFactory.CreateDatabase();

// This works
DbCommand dbCommand2 =
db.GetStoredProcCommand("HTMLGetPageIDFromName");
db.AddInParameter(dbCommand2, "@PageName", DbType.String, PageName);
object value2 = db.ExecuteScalar(dbCommand2);

// This does not work
DbCommand dbCommand3 =
db.GetStoredProcCommand("HTMLGetPageIDFromName",
new SqlParameter("@PageName", PageName));
object value3 = db.ExecuteScalar(dbCommand3);

The code that does not work causes an Exception on the
db.ExecuteScaler(dbCommand3)

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

Looking at the details I see there is an inner exception

{"Object must implement IConvertible."}

I have spent hours on this and I can not find anything specifc that is
causing the issue. It fails in both the November and December releases.

The exception comes from within the DBCommand.ExecuteScaler method call.

The example that fails loads the parameter types from the database and I
think this is causing the issue but I can not fix it.

Is this a known problem?

Cheers

Chris Crowe [IIS MVP 1997 -> 2006]
http://blog.crowe.co.nz
------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top