【发布时间】:2013-01-17 15:14:06
【问题描述】:
我不知道如何避免 SQL 注入,有人可以帮我解决我的问题吗?
这是我当前的代码:
Private Function INSERT() As String
Dim SQLcon As New SqlConnection
Dim SQLdr As SqlDataReader
Try
SQLcon.ConnectionString = "Data Source=#####;Initial Catalog=OJT;Persist Security Info=True;User ID=####;Password=#####"
Dim SQLcmd As New SqlCommand("INSERT INTO dbo.Patients(pIDNo,pLName,pFName,pMI,pSex,pStatus,pTelNo,pDocID,pAddr,pStreet,pBarangay,pCity,pProvince,pLNameKIN,pFNameKIN,pMIKIN,pRelationKIN) VALUES('" & LabelPNumber.Text & "','" & txtLname.Text & "','" & txtFname.Text & "','" & txtMI.Text & "','" & txtPatientSex.Text & "','" & txtPatientSex.Text & "','" & txtPatientTelNo.Text & "','" & txtPatientDoctor.Text & "','" & txtStreetNumber.Text & "','" & txtStreetName.Text & "','" & txtBarangay.Text & "','" & txtCity.Text & "','" & txtProvince.Text & "','" & txtKinLname.Text & "','" & txtKinFname.Text & "','" & txtKinMI.Text & "','" & txtRelationToPatient.Text & "') ", SQLcon)
SQLcon.Open()
MsgBox("Patient Added!", MsgBoxStyle.Information)
SQLdr = SQLcmd.ExecuteReader()
Catch ex As Exception
MessageBox.Show("Error Occured, Can't Add Patient!" & ex.Message)
Finally
SQLcon.Close()
End Try
Return "done"
End Function
【问题讨论】:
-
任何带有参数 sir rene 的 SELECT STATEMENT 示例?
-
其他同事指定,使用sql-parameters。我今天为this other question 写了一个样本,您可能也感兴趣。
-
还记得使用一个好的混淆器,因为 .net 应用程序很容易被反编译,从而泄露所有源代码和数据库的所有密码。混淆器不会解决这个问题,但会使它变得更加困难。无论如何,我不会将 .net 用于您提供给公众的数据库应用程序。
-
您可能对 Security.SE How can I explain SQL injection without technical jargon?上的这个相关问题感兴趣
标签: vb.net sql-server-2008 sql-server-2005 sql-injection