Validation errors when SQL query is formatted correctly - asp.net

I want to display the SQL correctly in my .aspx pages. But am getting a bunch of validation errors when I do. The code still appears to function correctly when running the page though. Here is what I mean:
If I had all of the SQL on one line then it works fine. When I try to format it correctly I am getting validation errors. How can I not get validation errors but display the query correctly?
This issue only seems to come up on longer queries.

Set the SelectCommand in the codebehind and use an # infront of a string (Literal String), but cannot be used in the xHTML.
SqlDataSource6.SelectCommand = #"
/* SQL Query Here */
";

Related

SSRS report fails to render via URL access unless View Report is clicked

The hyperlink to my SSRS report correctly renders parameters passed in on the URL query string. But the report does not render unless the View Report button is clicked. Other reports render as expected so I suspect something is wrong with the URL of the problem report:
http://reportserver/ReportServer/Pages/ReportViewer.aspx?%2fSales+Mgr+Reports%2fCustomer+Product+Variance+with+Net+Margin+Report&rs:Format=HTML4.0&rs:Command=Render&ReportType=PD&SortType=P&CurBeginDate=04/15/2013&CurEndDate=04/15/2014&CusCode=XXXXXXXXXX
That URL correctly fills the reports required parameters:
Why does this report fail to render even though I've included the command rs:Command=Render?
Thanks in advance.
Nevermind...I figured it out. Someone else might benefit though...
Blank parameters cannot be omitted from the query string. The two blank parameter boxes (Product Desc and Product ID) must be passed in with no value in order to make the render command work. It appears this is necessary even though those parameters are not required to run the report.
So the working query string has two (blank) parameters added on the end and looks like this:
http://reportserver/ReportServer/Pages/ReportViewer.aspx?%2fSales+Mgr+Reports%2fCustomer+Product+Variance+with+Net+Margin+Report&rs:Command=Render&rs:Format=HTML4.0&ReportType=PD&SortType=P&CurBeginDate=04/15/2013&CurEndDate=04/15/2014&CusCode=XXXXXXXXXX&ProdDesc=&ProdID=

Can I use request.querystring as a SQL query's parameter in ASP.NET?

In ASP.NET I want to make a query on request.querystring but it seems not work.
1.var search = Convert.ToString(Request.QueryString["search"]);
2.var query= db.product2s.SqlQuery("select * from product2s where tm ='{0}'",search);
In the webpage I set search="F112130601" ,on the serverside I can see that value request.querystring["search"] is "F112130601",but the server response no record result.
However if I change the code to below line, I can get response when I view the webpage there is some record results from the server.
1.var search="F112130601";
2.var query= db.product2s.SqlQuery("select * from product2s where tm ='{0}'",search);
I'm sory.I make a mistake with my query.
the problem is i should not use "" around product code,
http://test.com/home/product?search="F112130601"
when i use below code to access the server i get record
http://test.com/home/product?search=F112130601
thanks for all of your help.

xmlreader.Create return none

i am trying to read from xml string But ,
` XmlReader reader=XmlReader.Create(new StringReader(stringXml)`
reader is always none. why is reader objest none ?
You have to call the read function.
reader.Read();
Here is the answer for your question. There seems to be no problem and the XmlReader is ready to be utilized.
Actually, if you are open to use .NetFramework 3.5 and higher you could benefit from using Linq To Xml:
XElement x = XElement.Load(new StringReader(s));
this happened to me in code that had been working for years. there were two paths for populating the xml string used in creating the xReader. The first pulled xml from a text parameter. If the text parameter was empty then it would fetch the string from sql server. If the text parameter was null, however, then I was getting "none" from the xReader. This despite the fact that SQL return perfectly formed xml. If the text parameter was an empty zero-length string, however, then everything worked fine, that is, the fetch to SQL ran, fetch xml and loaded the reader. It was like the runtime .net engine was running both paths simultaneously and giving me the worst possible outcome, instead of the desired outcome.

SqlDataSource erroring when retrieving NVARCHAR(max) column

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.

asp.net dynamic data application won't accept input with "<" in it

I'm new to using asp.net dynamic data apps.. I just generated a simple app from my schema, and in one table I'm trying to insert a record where one of the fields is a varchar(255) field. I am finding that any input that has the "<" character in it will cause the app to throw an error when you try to save it, with the exception being if "<" is the last character in the input string.
Since the editinsert function is some ajax based call, it just gives me a generic javascript error indicating whatever webservice it tried to hit for the update threw a 500 error and I have no idea how to debug this.
I would guess it's one of two things:
1 - You're triggering asp.net's built-in request validation. You can turn it off by adding the following to your page:
<%# Page validateRequest="false" %>
(You can read more about it at http://www.asp.net/%28S%28ywiyuluxr3qb2dfva1z5lgeg%29%29/learn/whitepapers/request-validation/)
OR
2 - You're not using parameterized SQL querys so your doing something like:
"SELECT * FROM Customers WHERE FirstName = " + input
And this is causing invalid SQL when "input" has an SQL operator in it (such as ">")

Resources