Exporting and Importing a Customer SQL Server Database
How to pull a customer’s LabVantage database onto your own machine for troubleshooting or development — including the schema-rename problem nobody warns you about until you hit it.
01Why you’d do this
A customer reports a bug you can’t reproduce on your own reference database, or you’re planning an upgrade and want to rehearse it against real data before touching production. Either way, the answer is the same: get a copy of their database onto your own machine. The mechanics of a SQL Server backup and restore aren’t LabVantage-specific — but the moment you try to land two customer databases side by side on the same local SQL Server instance, or import a database whose original schema name collides with one you already have, you run into a problem that’s specific to how LabVantage stores its schema name inside the application data itself. Renaming a SQL Server schema after restore isn’t a built-in operation — it has to be done object by object.
This article covers both cases: the straightforward restore where you keep the original schema name, and the case where you need to rename it on the way in.
02Taking the export
If you’re the one pulling the export — on-site, or via remote access to the customer’s server — this part is plain SQL Server: right-click the database in Object Explorer, Tasks → Back Up…, full backup, and hand off the resulting .bak file. Nothing LabVantage-specific happens at this stage; treat it like backing up any other SQL Server database. The interesting decisions all happen on the import side.
03Two import paths
Which path you need depends entirely on whether the schema name in the backup is already free on your target instance.
Same schema name
You’re restoring one customer’s database and nothing else on this instance uses that schema name. Restore, fix the login mapping, done. See Same schema name.
Different schema name
You already have a database using that schema name, or you want a name that tells you at a glance which customer this is. Restore, then transfer every object into a freshly named schema. See Different schema name.
04Path A — restoring with the same schema name
-
Restore the database
In SSMS, right-click Databases → Restore Database…, point at the
.bakfile, and restore under whatever database name you want locally. - Create a matching login Under Security → Logins → New Login…, create a SQL login with the same name as the schema owner in the source database.
-
Fix the orphaned user
A restored database’s internal user still points at the old server’s login SID, not your new local login — even though the names match. You’ll know this has happened if the new login can’t connect. Re-link it from a query window connected as
sa:
That’s it for the simple case — the restored database is now usable with a login local to your machine, under its original schema name.
05Path B — renaming the schema on the way in
SQL Server has no built-in “rename schema” command — only ALTER SCHEMA…TRANSFER, which moves objects one at a time. To rename an entire schema you script that transfer across every table and stored procedure it contains. Below is the procedure I use for exactly that.
- Restore and re-link the login Same as Path A, steps 1–3 — get the database usable under its original schema name first.
- Create the target schema and its owner Under Security → Users, create the new login/user if it doesn’t exist yet. Under Schemas, create the new schema and set that user as its owner. Double-check the user’s default schema is set correctly before moving on — this is the setting that quietly causes “invalid object name” errors later if it’s wrong.
- Install and run the transfer procedure Create the stored procedure below inside the restored database (it only needs to exist there once), then call it to move every table and routine from the old schema into the new one.
It’s almost always the target schema or its owner being misconfigured — go back and confirm the new schema exists, its owning user exists, and that user’s default schema is actually set to the new schema before re-running. The procedure is safe to re-run: anything already transferred simply won’t show up in the cursor’s source list a second time.
06Reconnecting the database to LabVantage
Once the schema is sitting where you want it, the rest is the same application-server work as connecting any new LabVantage database: create a datasource on your JBoss instance pointing at this schema, then register it in the LabVantage Console with the matching database ID, JNDI name, and credentials. If you haven’t set up that connection before, see Setting Up Your Database Server for LabVantage for the datasource and schema-ownership groundwork this builds on.
07Checklist
- Backup restored under a database name you’ll recognize six months from now
- Login created locally and re-linked with
sp_change_users_loginif orphaned - Target schema exists, with an owner whose default schema is set correctly — checked before running the transfer
- Every table and routine confirmed moved (query
Information_Schema.tables/.routinesfor the old schema name — it should return nothing) - JBoss datasource and LabVantage Console database registration point at the correct schema name and credentials
08Field notes
What actually bites people
- The orphaned-user error message doesn’t mention orphaning at all — it just looks like a bad password. If a freshly restored login “won’t authenticate” even though you’re certain the password is right, check for an orphaned SID first.
- Give renamed schemas an obvious naming convention tied to the customer, not the database version or date — you’ll thank yourself the next time three customer copies are sitting on the same dev instance at once.
- Run the object count check in the checklist above every time. A transfer that silently skips one stored procedure because of a permissions issue is a debugging session waiting to happen weeks later.
