Click here to Skip to main content
15,887,746 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: the usual annoying absurdity Pin
F-ES Sitecore3-Jun-15 23:51
professionalF-ES Sitecore3-Jun-15 23:51 
AnswerRe: the usual annoying absurdity Pin
Richard Deeming4-Jun-15 0:34
mveRichard Deeming4-Jun-15 0:34 
QuestionC# PDF Printing Pin
El Developer3-Jun-15 4:54
El Developer3-Jun-15 4:54 
AnswerRe: C# PDF Printing Pin
F-ES Sitecore3-Jun-15 5:01
professionalF-ES Sitecore3-Jun-15 5:01 
GeneralRe: C# PDF Printing Pin
El Developer3-Jun-15 5:09
El Developer3-Jun-15 5:09 
GeneralRe: C# PDF Printing Pin
F-ES Sitecore3-Jun-15 5:18
professionalF-ES Sitecore3-Jun-15 5:18 
AnswerRe: C# PDF Printing Pin
Richard MacCutchan3-Jun-15 5:20
mveRichard MacCutchan3-Jun-15 5:20 
QuestionExecuteNonQuery SQL injection error from concatanating C# client values into a hard coded SQL string making a call to a SQL server. Pin
Stephen Holdorf3-Jun-15 4:43
Stephen Holdorf3-Jun-15 4:43 
I posted a message in the SQL forum but I think it was the wrong place. This is my problem. When I do an ExecuteNonQuery statement string from a c# client I am adding C# variables to the hard coded ExecuteNonQuery statement from the client as such:

string sqlQuery = "UPDATE rights SET category_key = " + toCat + " WHERE rights_key = @rights_key";
QueryContainer Instance = new QueryContainer(sqlQuery);

ExecuteNonQuery(sqlQuery);

<pre>

Also when  I do an SQL ExecuteScaler statement I am using from a C# client I am adding C# variables to the hard coded values in the SQL statement Execute ExecuteScaler client like this:

<pre>

queryString.Append(" SELECT isnull(");
queryString.Append("    (SELECT CASE WHEN convert(smalldatetime, '" + valDateMaterialRequired + "')  < (getdate() + isNull(hier_asp_config.late_days_num, 3)) THEN '1' ELSE '0' END");
queryString.Append("    FROM hier_asp_config ");
queryString.Append("    WHERE asp_key = " + aspKey + " )");
queryString.Append(" , CASE WHEN convert(smalldatetime, '" + valDateMaterialRequired + "')  < (getdate() + 3) THEN '1' ELSE '0' END)");


 return ExecuteScaler(queryString.ToString()).ToString();

<pre>

Now in the Class that calls the actual SQL I am using these techniques:

<pre>

protected int ExecuteNonQuery(string queryString)
        {
            int returnValue = 0;

            if (!_iserror)
            {
                if (_trace)
                    DoTrace("TAMIS.Data.Loader.ExecuteNonQuery", queryString);

                if (_connection == null || _connection.State == ConnectionState.Closed)
                {
                    OpenConnection();
                }

                DbCommand command = _provider.CreateCommand();
                command.Connection = _connection;
                command.CommandText = queryString;
                command.CommandType = CommandType.Text;
                if (_useTransaction) { command.Transaction = _transaction; }

                try
                {
                    returnValue = command.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    if (e is EntryPointNotFoundException)
                        throw e;
                    //if (_useTransaction == true)
                    //    _transaction.Rollback();
                    RollBack();
                    LogBLL bll = new LogBLL();
                    bll.WriteErrorLog(e);
                    _iserror = true;
                }
                finally
                {

                    if ((!KeepAlive && _connection.State == ConnectionState.Open) || _iserror == true)
                    {
                        CloseConnection();
                    }

                }

            }
            else
            {
                returnValue = -1;
            }

            return returnValue;
        }
<pre>

And this:

<pre>
protected object ExecuteScaler(string queryString)
        {

            object returnValue = null;
            if (!_iserror)
            {
                if (_trace)
                { DoTrace("TAMIS.Data.Loader.ExecuteScalar", queryString); }

                if (_connection == null || _connection.State == ConnectionState.Closed)
                {
                    OpenConnection();
                }

                DbCommand command = _provider.CreateCommand();
                command.Connection = _connection;
                command.CommandText = queryString;
                command.CommandType = CommandType.Text;
                if (_useTransaction) { command.Transaction = _transaction; }

                try
                {
                    returnValue = command.ExecuteScalar();
                }
                catch (Exception ex)
                {
                    if (ex is EntryPointNotFoundException)
                        throw ex;
                    //if (_useTransaction == true)
                    //_transaction.Rollback();
                    RollBack();

                    LogBLL bll = new LogBLL();
                    bll.WriteErrorLog(ex);

                   _iserror = true;
                }
                finally
                {

                    if ((!KeepAlive && _connection.State == ConnectionState.Open) || _iserror == true)
                    {
                        CloseConnection();

                    }

                }
            }
            else
            {
                returnValue = -1;
            }

            return returnValue;
        }
<pre>

These are clearly giving me SQL injection errors. In my case I cant change the code to stored procedures like they should be so How do I make the C# variable values from my client calling code and still work but not give me SQL injection errors?

AnswerRe: ExecuteNonQuery SQL injection error from concatanating C# client values into a hard coded SQL string making a call to a SQL server. Pin
Richard Deeming3-Jun-15 4:52
mveRichard Deeming3-Jun-15 4:52 
QuestionAzure storage-blob for basic asp.net MVC5 dynamic Website? Pin
apoxe3-Jun-15 4:37
apoxe3-Jun-15 4:37 
QuestionRunning MP4 video from the web. app. Pin
esb772-Jun-15 3:26
esb772-Jun-15 3:26 
GeneralRe: Running MP4 video from the web. app. Pin
Richard MacCutchan2-Jun-15 5:23
mveRichard MacCutchan2-Jun-15 5:23 
AnswerRe: Running MP4 video from the web. app. Pin
F-ES Sitecore2-Jun-15 5:31
professionalF-ES Sitecore2-Jun-15 5:31 
QuestionA bit lost here... Pin
Kornfeld Eliyahu Peter2-Jun-15 1:22
professionalKornfeld Eliyahu Peter2-Jun-15 1:22 
SuggestionRe: A bit lost here... Pin
Richard Deeming2-Jun-15 5:54
mveRichard Deeming2-Jun-15 5:54 
GeneralRe: A bit lost here... Pin
Kornfeld Eliyahu Peter2-Jun-15 20:28
professionalKornfeld Eliyahu Peter2-Jun-15 20:28 
QuestionRegarding one to one Video calling with Chat Pin
Usefuldesk2-Jun-15 1:22
Usefuldesk2-Jun-15 1:22 
SuggestionRe: Regarding one to one Video calling with Chat Pin
Richard MacCutchan2-Jun-15 2:29
mveRichard MacCutchan2-Jun-15 2:29 
QuestionAdd windows form module in Web application Pin
Aniiil1-Jun-15 22:33
Aniiil1-Jun-15 22:33 
Answer[repost] Pin
F-ES Sitecore2-Jun-15 0:43
professionalF-ES Sitecore2-Jun-15 0:43 
GeneralRe: [repost] Pin
Aniiil2-Jun-15 0:58
Aniiil2-Jun-15 0:58 
QuestionDesign view for MVC its now 2015 Pin
Member 117338681-Jun-15 10:26
Member 117338681-Jun-15 10:26 
AnswerRe: Design view for MVC its now 2015 Pin
F-ES Sitecore1-Jun-15 22:28
professionalF-ES Sitecore1-Jun-15 22:28 
GeneralRe: Design view for MVC its now 2015 Pin
Member 117338682-Jun-15 12:08
Member 117338682-Jun-15 12:08 
GeneralRe: Design view for MVC its now 2015 Pin
F-ES Sitecore2-Jun-15 12:23
professionalF-ES Sitecore2-Jun-15 12:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.