[RESOLVED]Database argument error

Hello everyone. I’ve recently have encountered an "invalid argument, Argument # = 1,Name of function(if known) = like ]" error when trying to delete rows from one of my tables. The project is a simple hobby project that uploads files to a "FileInformation"
table and later retrieves them for download, displayed in a web grid. Everything works as expected but now I’ve ran into this error when attempting to delete a row from this table, forcing me to drop and recreate the whole table if I want to remove uploaded
files. I’m assuming one of my additions is not playing well with the webmatrix databasemanager but I haven’t been able to nail which one. I’ve provided the detailed error below as well as the upload code and download code(adapted from mikesdotnetting’s upload/download
tutorial) that accesses the FileInformation table.

Error:

The specified argument value for the function is not valid. [ Argument # = 1,Name of function(if known) = like ]

System.Data.SqlServerCe.SqlCeException (0x80004005): The specified argument value for the function is not valid. [ Argument # = 1,Name of function(if known) = like ]
   at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)
   at System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan()
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()
   at Microsoft.WebMatrix.DatabaseManager.SqlCeDatabase.SqlCeDatabaseProvider.DeleteRowInternal(DbConnection connection, DbTransaction transaction, String tableName, String schema, IList`1 columnDataInfoList)
   at Microsoft.WebMatrix.DatabaseManager.SqlCeDatabase.SqlCeDatabaseProvider.DeleteRow(String connectionString, String tableName, String schema, IList`1 columnDataInfoList)
   at Microsoft.WebMatrix.DatabaseManager.IisDbManagerModuleService.DeleteRow(DatabaseConnection databaseConnection, String tableName, String schema, ArrayList columnDataInfoArrayList, String configPathState)
   at Microsoft.WebMatrix.DatabaseManager.Client.ClientConnection.DeleteRow(String tableName, String schema, ArrayList columnDataInfoArrayList)
   at Microsoft.WebMatrix.DatabaseManager.Client.ClientTable.DeleteRow(ArrayList columnDataInfoArrayList)
   at Microsoft.WebMatrix.DatabaseManager.Client.DataView.DoDelete(RowData rowData)

Upload code:

@{ 
    int id = 0;
    var fileName = "";
    var fileMime = "";<!--Describes file type-->
    var userName = "";
    
   if (IsPost) {
        var uploadedFile = Request.Files[0];
        DateTime fileDate = DateTime.Now; // Adds date
        userName = WebSecurity.CurrentUserName; // Adds username of uploader
        fileName = Path.GetFileName(uploadedFile.FileName);
        if(fileName != String.Empty)
        {
            fileMime = uploadedFile.ContentType;
            var fileStream = uploadedFile.InputStream;
            var fileLength = uploadedFile.ContentLength;
            
            byte[] fileContent = new byte[fileLength];
            fileStream.Read(fileContent, 0, fileLength);
            var db = Database.Open("ProjectDatabase");
            var sql = "INSERT INTO FileInformation (FileName, FileContent, MimeType, FileDate, UserName) VALUES (@0,@1,@2,@3,@4)";
            db.Execute(sql, fileName, fileContent, fileMime, fileDate, userName);
            id = (int)db.GetLastInsertId();
        }
    }
}

Download Page:

/*#################Call database####################################*/
        var db = Database.Open("ProjectDatabase");
        var populatequery = "SELECT FileDate, FileName, UserName, FileId FROM FileInformation";<!--Simple Query for my data-->
        var data = db.Query (populatequery);
        var grid = new WebGrid(source:data, defaultSort: "FileDate");<!--Creates a Grid for my DB data-->
/*#####################Changes sorting order############################*/
if (Request.QueryString[grid.SortDirectionFieldName].IsEmpty()) 
  {
    grid.SortDirection = SortDirection.Descending;
  }
/*##########################Secure page from non-members#####################*/
if (!WebSecurity.IsAuthenticated) {
        Response.Redirect("~/Security/SecurityDownloadPage?returnUrl="
            + Request.Url.LocalPath);
    }
   
}

<!--################################Grid Layout################################################-->

<h1>Downloads:</h1>
<div id = "grid"><h3>
@grid.GetHtml(
    tableStyle: "table",
    alternatingRowStyle: "alternate",
    headerStyle: "header",
    columns:grid.Columns(
    grid.Column("FileDate", "File Date"),
    grid.Column("FileName", "File"),
    grid.Column("UserName", "Uploader"),
    grid.Column("FileId","FileDownload", format:@<a href="Download.cshtml?Id= @item.FileId">Download</a>)
    )

)

LearningRobot

I’ve ran into this error when attempting to delete a row from this table

How do you attempt to delete the row? By code or using WebMatrix? If the latter, what happens if you try with code?

I’ve only attempted using WebMatrix but after reading your post, I put a quick delete code and statement together, which to my surprise actually removes the desired entries with no problems. I’m glad I’ve gained that necessary functionality back but I’m
still in the dark as to why I’m getting an error when I attempt the row delete via WebMatrix. Is this something outside of my code, thus I should just move on or should I keep investigating?(I’ve tested all the functionality of my code and everything works
as it should.)

LearningRobot

I’ve only attempted using WebMatrix but after reading your post, I put a quick delete code and statement together, which to my surprise actually removes the desired entries with no problems. I’m glad I’ve gained that necessary functionality back but I’m
still in the dark as to why I’m getting an error when I attempt the row delete via WebMatrix. Is this something outside of my code, thus I should just move on or should I keep investigating?(I’ve tested all the functionality of my code and everything works
as it should.)

The database manager in Webmatrix is pretty hit and miss. I generally write up my SQL queries and run within my application. You can always look at using the SQL Server Compact Edition Toolbox.. I find it helpful for scripting out SQL from my dev environment: http://sqlcetoolbox.codeplex.com/

Cheers!

Guess I’ll start developing the habit of writing and relying on my own SQL queries first and foremost, to avoid issues like this in the future. I’ll also look into the toolbox you linked a-rod, thanks. This pretty much wraps up this problem, I’ll go ahead
and mark this thread as answered…though the answer being a question that lead to a resolution might strange. I’ll let the mods decided if that’s alright.

Thanks Mike and A-rad.

LearningRobot

Guess I’ll start developing the habit of writing and relying on my own SQL queries first and foremost, to avoid issues like this in the future. I’ll also look into the toolbox you linked a-rod, thanks. This pretty much wraps up this problem, I’ll go ahead
and mark this thread as answered…though the answer being a question that lead to a resolution might strange. I’ll let the mods decided if that’s alright.

Thanks Mike and A-rad.

No worries mate – You should be able to get away with most of the things you want to do in Webmatrix. Bare in mind that it is only designed for basic application building (as it’s got IIS express, SQL CE built in)..

Over time you may want to look at using VS Studio for Web, hosting your site on a local IIS server and your data in an SQL Express Database (free).. Plenty of resources available to assist in the migration.

Cheers!

Leave a Reply