My Database was attacked by Sql Injetion.It makes lot of problem.
please Tell me how to stop Sql Injection attacks.
Thanks!..
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rodrigo Bereta40 reputationPosted Mar 22, 2013, 5:13 AM EDT
Sreejesh SPRank #1,975 · 740 reputationPosted Mar 22, 2013, 8:59 PM EDT
We have to block sql query,that is first of sql injection prevention
that code is
private bool validatextbox()
{
int f = 1;
String str = txtsearchitem.Text;
string[] words = str.Split(';');
foreach (string word in words)
{
string sql = word;
var p = new TSql100Parser(true);
IList
p.ParseStatementList(new StringReader(sql), out errors);
if (errors.Count == 0)
{
f = 0;
break;
}
}
if (f == 0)
{
return false;
}
else
{
return true;
}
}
the abode code use namespace are
using Microsoft.Data.Schema.ScriptDom;
using Microsoft.Data.Schema.ScriptDom.Sql;
so please add refernce these two namespaces then check your text box entry for the above code
that is
private void btnsearch_Click(object sender, EventArgs e)
{
bool result = validatextbox();
if (result == true)
{
}
}
the result is true you enter sql query then blocked
else continue the operation
so please try this code
Thanks
Sreejesh
Rodrigo Bereta40 reputationPosted Mar 23, 2013, 5:13 AM EDT
Title:
SQL Injection Attacks and Defense, Second Edition
Link:
http://books.google.com.br/books?id=KKqiht2IsrcC&printsec=frontcover&hl=pt-BR&source=gbs_ge_summary_r&cad=0#v=onepage&q&f=false
Regards