SqlDataSource erroring when retrieving NVARCHAR(max) column - asp.net

I'm writing a small ASP .Net application in order to retrieve data from a SQL database. The application uses drop downs in order to select what the next drop down should contain and when a page is selected, it should retrieve the HTML from the database. Everything is working until it gets to the retrival of the HTML data. When I try to retrieve the data, I get:
Microsoft JScript runtime error:
Sys.WebForms.PageRequestManagerServerErrorException:
An unknown error occurred while
processing the request on the server.
The status code returned from the
server was: 500
The HTML column is a defined as NVARCHAR(MAX), but I can't see this causing a problem. The application works if I set the DataValueField to another column. Has one else come across a problem like this? Maybe someone could shine some light on this?

One thing I noted when dealing with varchar(max) columns is that the framework still commonly expects to have a size associated with it. What I ended up having to do was specify the length as -1 to get it to accept a varchar(max) field. Your error message doesn't indicate that this is the problem, but you might try experimenting with it rather than turning off the validation, which could possibly have other repercussions.

Figured it out. Just needed to set ValidateRequest to false at the Page level.

Related

SSRS - Pass Multi Value Parameter with Available Values Option Enabled Through Querystring

I have one Parameter on my report, that has multi value on.
And it's values came from a Dataset.
On my application, when I request a report, this parameter goes as an Querystring value. But when I use the multi value option, the parameter is not a single value anymore, but an "array" with multiple values (Of Couse).
REPORT?codArea=&codDiretoria=17&ultimaAlteracao=on&formato=PDF&codListaPrioridade=8&codListaPrioridade=13
Important Part:
(codListaPrioridade=8&codListaPrioridade = 13)
The issue, is the "Available Values" option. The Parameter having an Array as a value, don't have any of the "Available Values" and SSRS throw a error.
Important Part:
System.ServiceModel.FaultException: This report requires a default or user-defined value for the report parameter 'codListaPrioridade'. To run or subscribe to this report, you must provide a parameter value.
If i disable the "Available Values" option, i can send this "array" without any issue:
codArea=&codDiretoria=17&ultimaAlteracao=on&codListaPrioridade=9&codListaPrioridade=13&formato=PDF
Important Part:
(codListaPrioridade=9&codListaPrioridade=13)
="----> "& Join(Parameters!codListaPrioridade.Value, ",")
The trick is that I need create in this report, this parameter with "Available Values" enabled, but this parameter need to accept "Any" values (Because the Array that is coming on querystring).
The "Available Values" must be used to show which values are available only (Inside my application).
Inside SSRS, the parameter works fine, the issue only occurs when using this report in my application, sending the parameters values in a querystring.
The key part of the error is "This report requires a default or user defined value for the report parameter."
You don't need a default parameter. It sounds to me like your application is passing an invalid parameter value to the report. The reason it works when you disable the available values is because then it will accept ANY value at all.
Run the query that populates the available values and keep it open.
Set a breakpoint in your ASP.NET code just before it passes the values to the report server. Examine what those values are and make sure it isn't trying to pass anything that ISN'T in the list of available values you got from running the query.
If there is something different then that is the cause of your error. I can't remember off the top of my head if casing matters so you'll want to check that too. And if you check them and everything is fine... check them again. I don't know how many times I've thought there wasn't any data out of place only to suddenly see it later.
An alternate theory would be that you just aren't passing the multi-value parameter to the report server correctly. I've never tried to do it directly in the URL before but on the MSDN page Pass a Report Parameter Within a URL in the "other examples" section it shows passing a multi-value parameter. In their example they seem to append a number to the end of the parameter name for each value. But I'm not sure if that is right either.
https://myserver/Reportserver?/SQL+Server+User+Education+Team/_ContentTeams/folder123/team+project+report&teamgrouping2=xgroup&teamgrouping1=ygroup&OrderID=747&OrderID=787&OrderID=12
But since you're already writing .NET code let me make a suggestion. Use the webservice as a webservice. It makes things like this so much easier. You just add the web service as a reference to the project and then basically call it like any other .NET class. The reference reads the WSDL file and shows you all of the available API calls and their parameters and what you'll get back. It really is quite a nice feature. Check out this MSDN article on "How to: Add a Reference to a Web Service" and then this TechNet dev guide: https://technet.microsoft.com/en-us/library/bb522713.aspx

ASP.NET DetailsView Update exception handling - truncated data

I'm using a DetailsView for updating a record. If the edit input of some fields is too long, the system produces a "data will be truncated" exception.
I can see where I can detect the error in DetailsViewItemUpdating or DetailsViewItemUpdated, and provide a user message. However, I believe the visual feedback should be sufficient for this release, i.e. "hey, it didn't take my 30 characters, even though the header label said it would only allow 20".
Is there a way to force the DetailsView to do the truncation and accept the update?
Or some other approach to this data handling exception, which must be pretty common.
ANSWER: from Ammar Gaffar at EE:
Convert to template field
In EditItemTemplate
Set DataBindings > MaxLength property to desired max length of field
Works fine.

SQLDataSource parameter insertion: Sanitisation and formatting

I am building a Web application and I want to allow users to insert records into a database. The method that I came across is to take the information from text boxes and run this code:
SqlDataSource1.InsertParameters["ProductCode"].DefaultValue = txtProductCode.Text;
SqlDataSource1.InsertParameters["Name"].DefaultValue = txtName.Text;
SqlDataSource1.InsertParameters["Version"].DefaultValue = txtVersion.Text;
SqlDataSource1.InsertParameters["ReleaseDate"].DefaultValue = txtReleaseDate.Text;
try
{
SQLDataSource1.Insert();
}
...
If I try to inject some SQL I get the error message:
Message: String or binary data would be truncated. The statement has been terminated.
Does this method sanitise the parameters? I am having a hard time finding this information because I am not sure if there is still a way to get around this error. If it does not how should I go about sanitising the inputs?
Additionally, the ReleaseDate parameter seems to be currently reading as dd/MM/yyyy but is there a way to lock this so that the same code on a different system doesn't behave differently. I am worried that if the code is run on a system with different regional settings it will use a different format.
One of your field in the table is not long enough to insert the value. You need to check each of ProductionCode, name, Version and ReleaseDate for their length and increase them accordingly.
http://msdn.microsoft.com/en-us/library/aa196741(v=sql.80).aspx

Cannot find typenames ("cannot resolve symbol")

I have a site in ASP.NET using Telerik AJAX controls.
Despite the latest binary being added to the website project, my code (eg myRadGrid.Datasource = "";) shows a red line on type names as they cannot be found for some reason.
Can anyone possibly explain why or have experience in this sort of problem?
Thanks
Why are you assigning an empty string to the radgrid datasource property? Try setting it to null instead, which is what you do if you want to clear the data source...

Actionscript error

I have a flex application which is configured with blazeds sever and i am pulling images from remote database from my flex application, but as soon as i click the get image button to pull images it is giving some action script error.
TypeError: Error #2007: Parameter bytes must be non-null.
at flash.display::Loader/_loadBytes()
at flash.display::Loader/loadBytes()
I tried googling but couldn't found any solution.
Any help is appreciated.
You have a null parameter inside the function flash.display::Loader/loadBytes(). ;)
Short answer is that you're probably fetching the wrong url. Use firebug or Fiddler or something to determine whether the url is correct. If that's not the case, maybe you're not handling the right events.
Like the comments say, we need the code.
Thank You everyone it was a my code error, it give this error if no value is returned to load bytes . I was pulling a image from a table where no image was present and therefore returning null value in load bytes.

Resources