Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9150271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:35:25+00:00 2026-06-17T11:35:25+00:00

I am trying to log down sql that execute. I have a function call

  • 0

I am trying to log down sql that execute.

I have a function call LogGenerateReport(String Sql) that will do a insert process to save the data in a database.

The Problem i face is about the SQl ”.

For example:

INSERT INTO TABLE(Sql)
VALUE('SELECT * FROM Sales WHERE SalesID = 'ABC123';')

Its return me error and i know what happened because of the quote.
I try again inside my database where i open a new query and paste above sql and made some modification on it such as.

INSERT INTO TABLE(Sql)
VALUE('SELECT * FROM Sales WHERE SalesID = ''' + 'ABC123' + ''';')

Its return me expected result.

 Output:
|Sql                                          |
|SELECT * FROM Sales WHERE SalesID = 'ABC123';|

But back on my .aspx.cs page i have a string builder that store the executed query and before it executed, it need to save the query first.

For example:

System.Text.StringBuilder str = new System.Text.StringBuilder();
str.append("SELECT * FROM Sales WHERE SalesID = 'ABC123';");

api.LogGenerateReport(Convert.tostring(str));

Its return me error as like above because of the quote.

I try to figure it out to overcome this and my idea is

String TempSql = Convert.tostring(str);
TempSql.Replace("'","+'''");

I wont work because of the + symbol is at different position.

Is there any way to overcome this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:35:26+00:00Added an answer on June 17, 2026 at 11:35 am

    To succesfully log any and all SQL queries regardless of their content, you need to apply parameterized commands in the following way:

    using(var command = new SqlCommand(someSqlConnection))
    {
       command.CommandText = "INSERT INTO TABLE(Sql) VALUE(@Sql)";
       command.Parameters.AddWithValue("@Sql", "<any string>");
       command.ExecuteNonQuery();
    }
    

    That way you can avoid escaping anything with NON-STANDARD methods, and protect your code from SQL injection attacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to log the error that caused my process to shut down,
I am using hibernate and I am trying to log all the SQL that
I am trying to get JSON data from a string that I have created
I have been trying to parse Java exceptions that appear in a log for
I'm trying to log everything that happens in my application to two logs: one
I am trying to track down an issue with a cURL call in PHP.
I'm trying to show a timer to the user that counts down from 3
I have written down a program in c and I am trying to create
I am trying to break down a string into an array. This code below
I'm trying to shrink some databases down so that my developers can load them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.