|
-
October 16th, 2007, 03:56 AM
#1
Prevent injection MSSql server
Hello,
I wanted to ask if anyone knows of a way to prevent injection in an SQL SERVER 2005. I mean, is there any way to do all the blocking in the server and not have to escape each special character one-by-one?
For example, in PHP I used mysql_escape_string and automatically the string was OK to send to the database... Is there something similar in SQL Server?
Thank you
-
October 16th, 2007, 05:50 AM
#2
Re: Prevent injection MSSql server
It's up to the client to escape the query that it sends to the server. The server cannot know if the client meant for an extra apostrophe to be there or not.
If you're accessing the database through .NET, this is handled automatically when using the SqlCommand object and parameters:
Code:
SqlCommand command = new SqlCommand("SELECT a, b, c FROM table WHERE id = @id", connection);
command.Parameters.AddWithValue("@id", 123);
SqlDataReader reader = command.ExecuteReader();
-
October 16th, 2007, 08:23 AM
#3
Re: Prevent injection MSSql server
as andreasblixt said, the best way is to use parameterized queries.
In PHP: you can use: mssql_init,mssql_bind,mssql_execute functions.
-
October 17th, 2007, 10:57 AM
#4
Re: Prevent injection MSSql server
 Originally Posted by ktsirig
Hello,
I wanted to ask if anyone knows of a way to prevent injection in an SQL SERVER 2005. I mean, is there any way to do all the blocking in the server and not have to escape each special character one-by-one?
For example, in PHP I used mysql_escape_string and automatically the string was OK to send to the database... Is there something similar in SQL Server?
Thank you
if you want to avoid attack sql injection, you have to user place holder in your app and avoid to generate sql statements
it's wrong
Code:
strSQL="select * from table where field1='" & anydata & "'"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|