How do I re-write a SQL query as a parameterized query?

You need to use parameters instead of just concatenating together your SQL: using (SqlConnection con = new SqlConnection(–your-connection-string–)) using (SqlCommand cmd = new SqlCommand(con)) { string query = “SELECT distinct ha FROM app WHERE 1+1=2”; if (comboBox1.Text != “”) { // add an expression with a parameter query += ” AND firma = @value1 “; … Read more

How can I avoid SQL injection attacks in my ASP.NET application?

Even though your question is very generic, a few rules always apply: Use parameterized queries (SqlCommand with SqlParameter) and put user input into parameters. Don’t build SQL strings out of unchecked user input. Don’t assume you can build a sanitizing routine that can check user input for every kind of malformedness. Edge cases are easily … Read more

Is htmlspecialchars enough to prevent an SQL injection on a variable enclosed in single quotes?

The character that htmlspecialchars fails to encode the critical character \0 (NUL byte), \b (backspace), as well as the \ character. In order to exploit this, you need a statement with multiple injection points. With this you can escape the closing delimiter of one string literal and thus expand it up to the next starting … Read more

Is a SQLAlchemy query vulnerable to injection attacks?

The underlying db-api library for whatever database you’re using (sqlite3, psycopg2, etc.) escapes parameters. SQLAlchemy simply passes the statement and parameters to execute, the driver does whatever is needed. Assuming you are not writing raw SQL that includes parameters yourself, you are not vulnerable to injection. Your example is not vulnerable to injection.

Preventing SQL Injection in ASP.Net

Try using a parameterized query here is a link http://www.aspnet101.com/2007/03/parameterized-queries-in-asp-net/ Also, do not use OpenQuery… use the this to run the select SELECT * FROM db…table WHERE ref = @ref AND bookno = @bookno More articles describing some of your options: http://support.microsoft.com/kb/314520 What is the T-SQL syntax to connect to another SQL Server? Edited Note: … Read more