Error - Must declare the scalar variable "@published"

Feb 26, 2010 at 6:52 AM

I've just edited the source code to add "ModifiedBy" and "HasBeenModified" fields to the Post class and database, but I'm getting an issue when trying to save posts using both the admin interface and Windows Live Writer.

Please thake the time to look at my edited files from the source code: Post.cs (lines 64-76 and 244-256) and DbBlogProvider.cs (the methods "SelectPost", "InsertPost", and "UpdatePost", on lines 88, 250, and 366).  Also note the new database fields in the dbo.be_Posts: ModifiedBy (nvarchar(50), null), and HasBeenModified (bit, null).

Now, whenever I try to add or edit a post, I get the following error: "Message : Must declare the scalar variable "@published"."

Full stack trace:

Url : http://localhost/admin/Pages/Add_entry.aspx

Raw Url : /admin/Pages/Add_entry.aspx

Message : Exception of type 'System.Web.HttpUnhandledException' was thrown.

Source : System.Web

StackTrace : at System.Web.UI.Page.HandleError(Exception e)

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

at System.Web.UI.Page.ProcessRequest()

at System.Web.UI.Page.ProcessRequest(HttpContext context)

at ASP.admin_pages_add_entry_aspx.ProcessRequest(HttpContext context)

at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

TargetSite : Boolean HandleError(System.Exception)

Message : Must declare the scalar variable "@published".

Source : .Net SqlClient Data Provider

StackTrace : at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)

at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

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.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)

at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()

at BlogEngine.Core.Providers.DbBlogProvider.InsertPost(Post post) in E:\Documents\My Dropbox\BlogEngine.Core_1.6\BlogEngine.Core\Providers\DbBlogProvider.cs:line 345

at BlogEngine.Core.Post.DataInsert() in E:\Documents\My Dropbox\BlogEngine.Core_1.6\BlogEngine.Core\Post.cs:line 857

at BlogEngine.Core.BusinessBase`2.Update() in E:\Documents\My Dropbox\BlogEngine.Core_1.6\BlogEngine.Core\BusinessBase.cs:line 345

at BlogEngine.Core.BusinessBase`2.Save(String userName, String password) in E:\Documents\My Dropbox\BlogEngine.Core_1.6\BlogEngine.Core\BusinessBase.cs:line 313

at BlogEngine.Core.BusinessBase`2.Save() in E:\Documents\My Dropbox\BlogEngine.Core_1.6\BlogEngine.Core\BusinessBase.cs:line 288

at admin_entry.btnSave_Click(Object sender, EventArgs e)

at System.Web.UI.WebControls.Button.OnClick(EventArgs e)

at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

TargetSite : Void OnError(System.Data.SqlClient.SqlException, Boolean)

I would really appreciate any help, as this did actually work at some point... maybe I've missed something in another file?

Coordinator
Feb 26, 2010 at 7:06 AM

I see an error for InsertPost in your DbBlogProvider.  You have this:

DbParameter dpHasBeenModified = provider.CreateParameter();
dpPublished.ParameterName = parmPrefix + "hasBeenModified";
dpPublished.Value = post.HasBeenModified;
cmd.Parameters.Add(dpHasBeenModified);

Those two bolded parts should instead be dpHasBeenModified.  Obviously, a small oversight that is easy to make!

In UpdatePost(), this problem is not there.

Feb 26, 2010 at 7:09 AM

I feel like a right prat now! :p ...the woes of copy and paste!

Thanks very much... just proves that all it takes is a 2nd look from someone else!