Skip to content

Convert MDF to SDF

Transfer SQL Server MDF data into a legacy SQL Server Compact SDF database.

Convert MDF files online

We don’t have a dedicated online converter for MDF to SDF yet, but you can convert MDF files online to these formats:

Want to convert MDF to SDF?

Let us know. We pick the conversions to add next by how many people ask for them.

How to convert mdf to sdf file

An application that uses SQL Server Compact may require an .sdf file instead of a server-hosted SQL Server database. The conversion transfers schema and data from an attached .mdf database; changing the extension cannot perform it.

What the MDF format is

.mdf is the primary data-file format for Microsoft SQL Server, including SQL Server Express and Developer editions. It stores relational database objects such as tables, indexes, constraints, and views. A database may also have an .ldf transaction-log file and one or more secondary .ndf data files.

An MDF normally must be attached to a compatible SQL Server instance before its contents can be queried or exported. Work on a copy when the file belongs to a production database, and keep the associated log and secondary data files available if the instance requires them.

What the SDF format is

In the database context, .sdf commonly identifies a SQL Server Compact database, formerly called SQL Server CE. SQL Server Compact is an embedded, single-file relational database for local desktop, mobile, and application storage; it does not require a continuously running SQL Server service.

An SDF is portable and simple to deploy, but SQL Server Compact is a legacy Microsoft technology with a smaller SQL feature set. SQL Server Compact 4.0 has a 4 GB maximum database size, restricted data types, and no equivalents for many server features. The target application must use the exact Compact version and provider it supports, commonly System.Data.SqlServerCe.4.0.

How to convert MDF to SDF

SQL Server Compact Toolbox is the most practical desktop option. It is available as a Visual Studio extension and in standalone distributions, although the software and SQL Server Compact runtime are legacy components. Install a version compatible with the source SQL Server and the destination application.

  1. Install SQL Server Express or another compatible SQL Server edition, then install SQL Server Compact Toolbox and the required SQL Server Compact runtime.
  2. In SQL Server Management Studio, select Databases → Attach, add the MDF copy, and confirm that the database opens. Supply the matching LDF or NDF files when SQL Server requests them.
  3. In SQL Server Compact Toolbox, add a connection to the attached SQL Server database. Create a new SQL Server Compact database, select the required Compact version, and choose an output name such as converted.sdf.
  4. Run the toolbox command for migrating or transferring a SQL Server database to SQL Server Compact. Select the required tables and preserve primary keys, identity behavior, indexes, and constraints where the destination supports them.
  5. Open the generated SDF in the toolbox. Check table and row counts, column types, primary keys, indexes, and representative values, then test the file with the target application before replacing any source database.

Toolbox releases differ in their migration commands. If a release cannot perform the transfer directly, create the SDF schema manually, export table data from SQL Server as CSV or scripted INSERT statements, and import it into the corresponding Compact tables. CSV is suitable only for data transfer; it does not preserve constraints, indexes, identity settings, or all data types.

For repeatable migrations, a custom .NET utility can read SQL Server through System.Data.SqlClient and write parameterized inserts through System.Data.SqlServerCe. Add explicit type mappings, batch inserts, identity handling, null handling, and post-import row-count checks rather than relying on implicit conversion.

A commercial desktop database converter such as Full Convert Enterprise may support SQL Server Compact as a destination, but verify support for the exact SQL Server and Compact versions before purchase. Reputable online services generally do not provide a dependable direct MDF-to-SDF migration, and uploading an MDF can expose credentials, personal data, and proprietary records; use a local tool for this format pair.

Compatibility and data-loss risks

SQL Server Compact cannot reproduce every SQL Server object. Stored procedures, user-defined functions, triggers, SQL Agent jobs, linked servers, replication, server-level permissions, full-text indexes, FILESTREAM data, and other instance-level settings must be redesigned, omitted, or kept in the application or source server.

Review unsupported or incompatible columns before migration. SQL Server types such as xml, sql_variant, CLR types, geography, hierarchyid, and some large or specialized types may require conversion to supported Compact types or storage outside the SDF. Recreate indexes and constraints after resolving definitions that the Compact engine cannot represent.

Security also changes. SQL Server uses server and database authentication and authorization, while an SDF is opened through the SQL Server Compact provider and can use database-level encryption. Update the application's connection string and provider reference, then test every query and write operation. Back up the MDF and validate row counts, key relationships, dates, Unicode text, binary values, and application behavior before deleting or overwriting source files.

Information about file extensions and file types is provided by File-Extensions.org

Additional formats for
mdf file conversion

Reverse conversion

Convert to sdf from
other formats

Share on social media:

Already downloaded

This file has already been downloaded. For your privacy it was deleted from our server right after the download, so it cannot be downloaded again. To get it once more, convert the file again.