public DataTable GetDataTable(string spname,string parameters)
{
DatatTable dt=new DataTable();
try
{
using(sqlcommand cmd=new sqlcommand("",conn))
{
ArrayList aParams;
string[] avalues=parameters.Split(new String[] {"_"},StringSplitOptions.None);
cmd.CommandType=CommandType.StpredProcedure;
cmd.CommandText=spname;
cmd.CommandTimeOut=Convert.ToInt32(ConfigurationManager.AppSettings[CommandTimeOut]);
aParams=GetParameterList(spname);
for(Int32 i=0;i
Note: I am getting SQL Injection issue on this line " strReader=cmd.ExecureReader();".Please give me some suggestion to resolve this SQL Injection issues.

Muhammad Imran AnsariPosted Jan 17, 2023, 2:06 PM
Hi Dibyajyoti,
This code has a major security vulnerability, it does not properly validate or sanitize the user input passed to the stored procedure which could lead to SQL injection attacks.
The problem is with the following line:
cmd.Parameters.Add(new SqlParameters((String)aParams[i],(String)aValues[i]));
I suggest using parameterized queries to protect against SQL injection attacks, also check if the input is valid before using it in SQL statement, and you should also consider logging any errors or exceptions that may occur during the execution of the function.
Dibyajyoti PalataPosted Jan 23, 2023, 5:47 PM
for(Int32 i=0;i
cmd.Parameters.Add(new SqlParameters((String)aParams[i],(String)aValues[i]));
}
In above method multiple SP calling based on SP multipule times adding parameter and values.So SQL Injection will prevent.
How to avoid sql injection ? Any predefine functions to handle dynamic parameter and value.
How to write sanitize method to handle that parameters ?
Please guid me.
Dibyajyoti PalataPosted Jan 17, 2023, 1:15 PM
I checked stored procedure working fine and also getting expacted output.
Naimish MakwanaPosted Jan 16, 2023, 8:09 AM
Please refer below link.
https://dba.stackexchange.com/questions/127/do-stored-procedures-prevent-sql-injection
Sachin SinghPosted Jan 16, 2023, 7:24 AM
There is no issue in the shared code.
I guess your stored procedure might have some issue, make sure you are not concatinating values using '+' sign in your stored procedure.