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 4552690
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:49:53+00:00 2026-05-21T16:49:53+00:00

I work on a ancient large WinForms project that contains a lot of win

  • 0

I work on a ancient large WinForms project that contains a lot of win form libraries.

Each form uses hard-coded sql commands in methods. Sometimes the same SQL strings are duplicated, and modifying one I should research “similar” strings in the form’s code.

I understand that the architecture is not super-pretty, but at moment we can’t perform large architecture modifications. I think to do “little steps” to ameliorate the separation o the UI and BD logic….

A first ‘step’, by eg. I thought “separate” in a way sql strings from code. How could this be achieved, using Resources, a special class, a XML file?

Variant I – using named Resources

' ancient variant '
_SqlPeriod = String.Format("SELECT * FROM DBO.GP_PERIOD WHERE PERIOD = {0} ORDER BY LABEL", Me._Period)

' a better way (?) ... '
_SqlPeriod = String.Format(My.Resources.ResourceManager.GetString("SelectAPeriod"), Me._Period)
  • 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-05-21T16:49:54+00:00Added an answer on May 21, 2026 at 4:49 pm

    Generally, your biggest concern is using String.Format to form your SQL queries, because this is prone to Sql Injection Attacks, if you don’t explicitly validate your parameters. So separating these strings is not an improvement (and moving them into an xml file would be a security disaster, if they are resolved during runtime).

    To prevent this, you need to either create SqlCommand instances and set parameters programatically (check MSDN – How To: Protect From SQL Injection in ASP.NET), or use a completely different approach and switch to an ORM framework.

    Since moving to ORM might take considerable amount of time if you haven’t used it before, I believe you will opt for the first option. In that case, simply switching to Sql parameters as described above will be an improvement (even with sql strings left hard-coded).

    To prevent duplication, you should consider moving all database access calls into a separate project (a Data Access Layer, DAL). If you want to start in smaller steps, you might consider (for start) delegating the creation of the SQL string to a different layer, e.g.:

    _SqlPeriod = QueryStrings.GetPeriodsById(Me._Period) ' <- returns an sql string
    

    This would allow you to move parameter validation into a common project. Later, you will want to avoid passing sql strings to your UI layer completely, and simply get the data:

    _ActualData = Dal.GetPeriodsById(Me._Period) ' <- gets the actual list of periods
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a client at work that uses an ancient tool to preview PDFs
My work place is developing code for some absolutely ancient hardware that doesn't have
Where I work, we use ancient technology that belongs in a museum. Further I
Work on C# Desktop project,I have an account on paypal ,From my desktop application
I work with unordered_set . Here it's written that it has a reserve function
We're updating our ancient internal PHP application at work. Right now, we gather extensive
Flowcharting. This ancient old practice that's been in use for over 1000 years now,
I am modifying an ancient table which has inline JavaScript in the form of
To my horror I've just found out that chr doesn't work with Unicode, although
We have a lot of automated spreadsheets that extract data, calculate forecasts, publish web

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.