English 中文(简体)
在拨打ExectureStoreQuery以避免 SQL 输入时, 我是否需要使用准美质化查询?
原标题:Do I need to use parametrized queries when calling ExectureStoreQuery to avoid SQL Injections?

我想知道,在从执行Stored程序处执行 sql 时,我是否需要使用参数化查询,以防止 SQL 喷射攻击?

根据这个""http://msdn.microsoft.com/en-us/library/dd487208.aspx" rel=“nofollow”>MSDN链接 ,我应该使用参数。

根据此", http://msdn.microsoft.com/en-us/library/ee358758.aspx" rel=“nofollow” > 其它 MSDN 链接 , 使用 {0} 的 sql 字符串相当于使用参数 。

所以在我的 SQL 语句中只包含一个 {0} 、 {1} 等是否真的正常 :

var rv = _context.ExecuteStoreQuery<int>("select ID from table where typeID = {0}", typeID);

或者我需要:

     var param = new SqlParameter("@typeID", SqlDbType.Int);
     param.Value = typeID;
     var rv = _context.ExecuteStoreQuery<int>("select ID from table where typeID = @typeID", param);
问题回答

它基本上归结为此。 您是否重复使用查询, 有很多电话, 但类型ID 的值不同? 那么是的, 它可能会在性能上产生微小的差别 。

另一方面,如果你只是打这个电话, 那么绝大多数的表演打击 将会是你的DB电话。

我个人还没有看到,这在过去8-10年中 写过的任何代码中 都产生了显著的改变。

所以,我投票 - 不用麻烦了。





相关问题
Proving SQL Injection

I m trying to simply prove here that this simple function isn t good enough to prevent every sql injection in the world: Function CleanForSQL(ByVal input As String) As String Return input.Replace(...

How to confirm SQL injection

Is there any way to confirm that a particular breach of security was done through SQL injection?

Restricting user password character set

Working on a login system - the point where customer chooses their password for site access. Beyond using RegEx to ensure that the password is strong enough, normally on our system all data that ...

Java - escape string to prevent SQL injection

I m trying to put some anti sql injection in place in java and am finding it very difficult to work with the the "replaceAll" string function. Ultimately I need a function that will convert any ...

Does this code prevent SQL injection?

Background I ve been contracted to analyze an existing Data Provider and I know the following code is faulty; but in order to point out how bad it is, I need to prove that it s susceptible to SQL ...

SQL Injection Vulnerability found

Yesterday i received an email from a guy that our site is vulnerable to SQL injection. The email said: I tried some classic SQL injection on your server. This URL contains the result: http:...

Vulnerability reports from PCI-DSS scan

We have had a PCI scan on one of our websites passed on to us by one of our clients. There are a number of reports of vulnerabilities that look something like this: Network service: 80/443 ...

Wordpress Database Output - Remove SQL Injection Escapes

I m having a problem using $wbdb. When I insert or update data using $wpdb->insert or $wpdb->update, the SQL injection protection actually inserts the into the database, and when outputting that ...

热门标签