Can someone inject sql code in a asp.net SQL Datasource?

Hi

I am currently refactoring our code on one of our applications and came across some asp.net<Sqldatasource>

this is the code

<asp:sqldatasource id="sds_Categories" runat="server"
                                        connectionstring="<%$ ConnectionStrings:Database %>"
                                        selectcommand="SELECT [SId], [Des] FROM [Categories] ORDER BY [seq]">
</asp:sqldatasource>

Could someone hack my database with this code?
EasyToHelpAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
you have to specifically define the selection criteria with parameters, that would increase the security of your connection.

example:
<asp:sqldatasource id="sds_Categories" runat="server" 
                                        connectionstring="<%$ ConnectionStrings:Database %>" 
                                        selectcommand="SELECT [SId], [Des] FROM [Categories] where compareField = @Value ORDER BY [seq]">
</asp:sqldatasource>

Open in new window

when you're establishing the connection, you can add:
sds_Categories.SelectParameters.Add("@Value", yourValue);

Open in new window

get the idea?
David Johnson, CD, MVPOwnerCommented:
one can never trust user entered data you must always validate it.
ZberteocCommented:
Specifically that query/command cannot be hacked or injected because it doesn't use any parameter with input from the user.  It simply executes a static query from a table to return 2 columns. It will always return the same thing unless the table content changes by other means.

in order ti hack/inject the SQL server it has to exist user input.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kamal KhaleefaInformation Security SpecialistCommented:
try to validate all the inputs from the user and filter them

also try to replace all special characters like '  ! -
käµfm³d 👽Commented:
Just to add to Zberteoc's comment, that "code" runs on the server, not the client, so no one will ever see it. Even though it appears to be HTML, it's really ASP.NET's syntax for embedding code elements into your .aspx pages. If someone on the outside is able to see those bits of code, then you've got bigger security issues going on.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.