OptimiDoc ships with SQL Server LocalDB so it runs out of the box with no separate database to install. LocalDB is fine for a pilot or a small site, but it is single-machine, size-limited and unattended-maintenance-free — which makes it unsuitable for production at scale or for a multi-node cluster. This guide explains how OptimiDoc uses its database and walks through migrating from LocalDB to a full SQL Server (or SQL Server Express) instance.
How OptimiDoc Uses the Database
OptimiDoc stores everything except spooled files in SQL Server: users, groups and departments; devices, rules and connectors; job metadata, accounting and reporting data; audit logs; and (because sessions are database-backed) user sessions. Two points matter for this migration:
-
The connection string lives in
web.config. The main database is configured by the connection string namedOptimiDoc.Dao.OptimiDocDbContext. Out of the box it points at LocalDB with the catalogoptimidocX(fileoptimidocX.mdfinApp_Data). Migrating simply means restoring that database onto SQL Server and repointing this connection string. -
Quotas use a second database. If you use print quotas, OptimiDoc keeps them in a separate database configured by the connection string named
OptimiDoc.Dao.QuotaDbContext(default catalogoptimidocQ). The presence of that connection string is what enables the quota feature. If you rely on quotas, migrate this database too — see Step 8.
OptimiDoc maintains its own performance indexes through Entity Framework migrations, which run automatically when the application starts against the new database — you do not create them by hand.
Why Migrate?
|
LocalDB |
SQL Server (Express / Standard) |
|---|---|
|
Maximum 10 GB database size |
Express: 10 GB; Standard and above: effectively unlimited |
|
Limited concurrent connections |
Hundreds of concurrent connections |
|
No unattended maintenance (index rebuild, backups) |
Full maintenance-plan and Agent support |
|
Local-only — no remote access |
Reachable from other servers |
|
Cannot be used by a multi-node cluster |
Required for a clustered / highly-available deployment |
Recommendation: migrate to SQL Server when your environment grows beyond a couple of dozen devices or a few hundred users, when you need scheduled backups and maintenance, or when you plan a multi-node cluster.
Prerequisites
-
SQL Server installed and running. SQL Server Express (free) suits most sites; Standard or above is recommended for large deployments.
-
SQL Server Management Studio (SSMS) for the backup/restore and permission steps.
-
Administrator access to both the OptimiDoc server and the SQL Server.
-
Sufficient disk space on the SQL Server (check the current LocalDB file size first).
Step 1 — Install SQL Server
If SQL Server is not already available:
-
Download SQL Server Express (or use a licensed Standard/Enterprise instance).
-
Run the installer and choose Basic or Custom installation.
-
Note the instance name (default:
SQLEXPRESS). -
Choose Windows Authentication or Mixed Mode as appropriate for your environment.
-
In SQL Server Configuration Manager, enable TCP/IP if OptimiDoc and SQL Server are on different machines.
-
Open port 1433 in the Windows Firewall if the SQL Server is remote.
Step 2 — Stop the OptimiDoc Application
-
Open IIS Manager, select the OptimiDoc site and click Stop.
-
Open the Services console and stop the OptimiDoc Service as well, so nothing writes to the database mid-migration.
-
Wait for active requests and jobs to finish.
Step 3 — Back Up the LocalDB Database
The LocalDB database files are in the OptimiDoc App_Data folder (for example C:\inetpub\wwwroot\OptimiDoc\App_Data), named optimidocX.mdf / optimidocX.ldf.
Method A — Backup and Restore (recommended)
-
In SSMS, connect to the LocalDB instance using the server name
(LocalDb)\v11.0(or(localdb)\MSSQLLocalDB, depending on your LocalDB version). -
Right-click the
optimidocXdatabase and choose Tasks > Back Up. -
Create a Full backup to a
.bakfile in a location the target SQL Server can read.
Method B — Detach and Attach
-
Detach the database from LocalDB.
-
Copy the
.mdf/.ldffiles to the SQL Server data directory. -
Attach the database on the target SQL Server instance.
Step 4 — Restore to SQL Server
Using Method A:
-
In SSMS, connect to the target SQL Server instance.
-
Right-click Databases and choose Restore Database.
-
Select Device, browse to the
.bakfile from Step 3, and confirm the destination database name (keepingoptimidocXavoids extra edits, but you may choose your own). -
Click OK and verify the database appears with all its tables.
Step 5 — Configure Database Permissions
-
In SSMS, expand Security > Logins on the SQL Server instance.
-
Create a login for the account OptimiDoc runs as:
-
Windows Authentication: add the IIS application-pool identity (for example
IIS AppPool\OptimiDoc) and the OptimiDoc Service account. -
SQL Authentication: create a SQL login with a strong password.
-
-
Map the login to the restored database with the db_owner role.
Step 6 — Update the Connection String
-
Open
web.configin the OptimiDoc web application root. -
Find the connection string named
OptimiDoc.Dao.OptimiDocDbContext. -
Replace its
connectionStringvalue with one that points at SQL Server, keepingproviderName="System.Data.SqlClient":
Windows Authentication:
Server=<sql-server>\SQLEXPRESS;Initial Catalog=optimidocX;Integrated Security=SSPI;
SQL Authentication:
Server=<sql-server>\SQLEXPRESS;Initial Catalog=optimidocX;User Id=optimidoc_user;Password=<password>;
-
Remove the LocalDB-specific
AttachDBFilename=|DataDirectory|\optimidocX.mdfpart — it does not apply to a full SQL Server instance. -
Save
web.config.
Step 7 — Start and Verify
-
Start the OptimiDoc Service and then the OptimiDoc site.
-
Browse to the console (it redirects to
/ui) and log in as administrator. On first start, OptimiDoc applies any pending migrations to the new database automatically. -
Confirm:
|
Check |
Expected result |
|---|---|
|
Login |
Administrator login succeeds |
|
Version / connection |
The System Info dashboard widget shows the running version |
|
Users |
All user accounts are present |
|
Devices |
All devices appear with correct status |
|
Job history |
Historical data is visible under Reports |
|
Rules |
All rules present and active |
|
Pull print |
Submit and release a test job successfully |
Step 8 — Migrate the Quota Database (If You Use Quotas)
If print quotas are in use, repeat the backup/restore for the quota database:
-
Back up the
optimidocQLocalDB database and restore it onto the same SQL Server (Steps 3–4). -
Grant the OptimiDoc login db_owner on it (Step 5).
-
In
web.config, add or update the connection string namedOptimiDoc.Dao.QuotaDbContextto point at the restoredoptimidocQdatabase (same server, same authentication style as the main connection). -
Restart OptimiDoc. Quota migrations run automatically; confirm quota balances and history are intact under the quota pages.
If you do not use quotas, there is no
optimidocQdatabase to move and noOptimiDoc.Dao.QuotaDbContextconnection string to add — skip this step.
Step 9 — Set Up Database Maintenance
Now that you are on SQL Server, configure regular maintenance (SQL Server Express has no Agent, so use Windows Task Scheduler with sqlcmd there):
-
Full backup — daily, retained for at least seven days (back up both
optimidocXand, if present,optimidocQ). -
Index rebuild — weekly, out of hours.
-
Update statistics — weekly, after the index rebuild.
-
Transaction-log backup — every 30 minutes if you use the Full recovery model.
Troubleshooting
|
Problem |
Solution |
|---|---|
|
"Login failed" after changing the connection string |
Confirm the login exists on SQL Server and is mapped to the database with db_owner |
|
"Cannot open database" |
The |
|
"A network-related error" |
Ensure SQL Server accepts remote connections (TCP/IP enabled) and port 1433 is open |
|
Quotas missing after migration |
The |
|
Slow performance after migration |
Rebuild indexes and update statistics; confirm the application started cleanly so its own index migrations applied |
In Summary
Migrating OptimiDoc off LocalDB is a database restore plus a connection-string change: back up the optimidocX database, restore it onto SQL Server, grant the OptimiDoc accounts db_owner, and repoint the OptimiDoc.Dao.OptimiDocDbContext connection string in web.config. If you use quotas, do the same for the optimidocQ database and its OptimiDoc.Dao.QuotaDbContext connection string. OptimiDoc applies its schema and index migrations automatically on first start, and a full SQL Server unlocks scheduled maintenance, remote access and clustering.
Related articles