Most estimates for a legacy migration count screens, forms and reports. The rules that make the system valuable are often somewhere else: in stored procedures and triggers that the application calls without knowing what they do. If you migrate the front end and leave that alone, nothing breaks. If you decide to move it, you need to know what is there first.
This tutorial walks through finding that logic, pinning its behavior with tests, and deciding what moves to .NET 8 and what stays in SQL Server. It assumes a VB6, WebForms, Classic ASP or Access front end over SQL Server. It does not apply to FoxPro systems with DBF files and no server engine; those have their own problem, which is covered in the FoxPro data post.
Why this logic gets missed
Three habits put rules in the database.
- A developer needed a change fast and a procedure was easier to deploy than a VB6 binary.
- A trigger was added so that every writer, including the nightly batch and ad hoc scripts, got the same rule.
- Reports were built on views that quietly apply filters, such as excluding voided orders.
The result is behavior that no one reads when they read the application code. Triggers are the worst case, because nothing in the calling code mentions them.
Step 1: Inventory what exists
Start with counts, by object type, including size. Run this against the production schema, or a restored copy.
SELECT o.type_desc,
COUNT(*) AS objects,
SUM(LEN(m.definition)) AS total_chars
FROM sys.sql_modules m
JOIN sys.objects o ON o.object_id = m.object_id
WHERE o.is_ms_shipped = 0
GROUP BY o.type_desc
ORDER BY total_chars DESC;
Then list triggers on their own, with the tables they sit on and whether they are enabled.
SELECT t.name AS trigger_name,
OBJECT_NAME(t.parent_id) AS table_name,
t.is_disabled,
OBJECTPROPERTY(t.object_id, 'ExecIsInsertTrigger') AS on_insert,
OBJECTPROPERTY(t.object_id, 'ExecIsUpdateTrigger') AS on_update,
OBJECTPROPERTY(t.object_id, 'ExecIsDeleteTrigger') AS on_delete
FROM sys.triggers t
WHERE t.is_ms_shipped = 0;
You will also want to know which procedures the application actually calls. Definitions alone do not tell you that. Capture a representative window with Extended Events, filtered to the application's login, and count executions per procedure. A week that includes month end is better than a quiet one. Procedures with zero calls in that window are candidates to confirm as dead, not to delete.
Step 2: Classify each object
Sort every procedure and trigger into one of four groups.
- Data access only. Selects, inserts and updates with no decisions. These are replaced by the new data layer.
- Business rules. Pricing, eligibility, status transitions, posting to a ledger. These are contracts.
- Integrity and audit. Triggers that maintain history tables, timestamps or denormalized totals.
- Operational. Cleanup, index maintenance, jobs. These stay with the database.
Look for tells in the text: IF and CASE chains on status codes, hardcoded customer or product IDs, RAISERROR with a business message, cursors, and dynamic SQL. Hardcoded IDs in particular mean a rule that someone special-cased years ago and the reason is gone.
Step 3: Pin behavior with tests before moving anything
Group 2 and 3 objects get characterization tests, in the same spirit as the HTTP harness for the web tier. The method is simple.
- Restore a copy of production to a test instance and scrub personal data.
- For each procedure, choose inputs from real rows, including the odd ones: nulls, zero quantities, voided records, old dates.
- Run it inside a transaction, capture the result sets, the return value and the changes to affected tables, then roll back.
- Store those captures as approved output files and compare on every run.
For triggers, the test is a write through the table: insert, update and delete a representative row, then diff every table that changed, not only the one you wrote to. A coding agent is useful for drafting the input matrix and the comparison code in bulk. It is not able to tell you which outputs are intended behavior and which are old bugs. That call belongs to an engineer who talks to the business owner.
Step 4: Decide what moves
There is no rule that says T-SQL has to go. Our default is the following.
- Move rules that change often, that need unit tests in CI, or that must also run in a code path outside SQL Server, such as an API that agents will call.
- Leave set-based work that is fast and stable in SQL, such as large aggregations. Rewriting it in C# usually makes it slower and gives you no benefit.
- Leave for now any rule whose owner cannot be found. Wrapping it and keeping it running costs little. Rewriting it from guesswork costs more.
When you do move a procedure, move it in a slice, not all at once. The old procedure stays in place and the harness compares the old and new results, the same way you compare web responses. Shadow runs against production data catch the cases your test inputs missed.
Step 5: Watch for the traps
- Triggers that fire twice. If the new code writes the same audit row the trigger already writes, you get duplicates. Decide who owns each side effect, and disable one.
- Implicit transactions. A procedure may rely on the caller's transaction scope. Check the behavior on error, not only on success.
- Collation and date handling. Comparisons that match in SQL Server may not match in .NET string code. Test with mixed case and accented values.
- Rounding.
DECIMALarithmetic in T-SQL anddecimalin C# can differ on intermediate precision. Test money calculations on real totals. - Permissions. Procedures may run under ownership chaining that the new application login does not have.
What you should have at the end
A spreadsheet or table listing every procedure and trigger, with its call count, its class, its owner, a test status and a decision. That list belongs in the assessment, because it moves the estimate. A system with 40 procedures that are mostly data access is a different job from one with 40 procedures that hold the pricing rules, and you cannot tell which you have by reading the screens.
If you have the second kind and no one on staff knows what the procedures do, that is a reasonable thing to bring to us. We would start by running the inventory above, which takes a few days, and you would have the list whether or not we continue.