none
The CREATE DATABASE statement failed : SqlServer 2012 Express

    Question

  • Hi

    My program  attempts to create a database programmatically  using SQL Server 2012 Express SP1 but fails with the following error message:

    ----------------------------------------------------------------------------------

    System.Data.SqlClient.SqlException: The CREATE DATABASE statement failed. The primary file must be at least 4 MB to accommodate a copy of the model database.

    ----------------------------------------------------------------------------------

    Would appreciate your help in resolving this issue.

    Thank you

    John B.

    Thursday, December 06, 2012 7:31 PM

Answers

  • When you execute a CREATE DATABASE statement, you can supply the initial size of the filegroups (primary, secondary, log, etc.).  If you do not supply size, it will inherit the default value, which is the size of the model DB.  It sounds like this parameter is getting set to a value smaller than 4MB, which is invalid, and thus the error.  Try removing the size parameter from your CREATE DATABASE statement.

    Thanks,
    Sam Lester (MSFT)


    My Blog

    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

    Thursday, December 06, 2012 7:52 PM
    Moderator
  • Hi

    My program  attempts to create a database programmatically  using SQL Server 2012 Express SP1 but fails with the following error message:

    ----------------------------------------------------------------------------------

    System.Data.SqlClient.SqlException: The CREATE DATABASE statement failed. The primary file must be at least 4 MB to accommodate a copy of the model database.


    in previous version of SQL Server the minimum size for database files were less than 4MB.

    Therefore I assume that you've ported your application from an older SQL Server version SQL Server 2012 Express.

    As Samuel already wrote, omit the size when creating the database to use the default size or specify a larger value than specified in the model database.

    As a side note - please look at the grow factory of the database and log file of the newly created database as the default as specified in model database are mostly stupid - initial size of 1MB for log and a grow factor of 10% are absolute stupid default settings.


    Please use Mark as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    Thursday, December 06, 2012 8:21 PM

All replies

  • When you execute a CREATE DATABASE statement, you can supply the initial size of the filegroups (primary, secondary, log, etc.).  If you do not supply size, it will inherit the default value, which is the size of the model DB.  It sounds like this parameter is getting set to a value smaller than 4MB, which is invalid, and thus the error.  Try removing the size parameter from your CREATE DATABASE statement.

    Thanks,
    Sam Lester (MSFT)


    My Blog

    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

    Thursday, December 06, 2012 7:52 PM
    Moderator
  • Hi

    My program  attempts to create a database programmatically  using SQL Server 2012 Express SP1 but fails with the following error message:

    ----------------------------------------------------------------------------------

    System.Data.SqlClient.SqlException: The CREATE DATABASE statement failed. The primary file must be at least 4 MB to accommodate a copy of the model database.


    in previous version of SQL Server the minimum size for database files were less than 4MB.

    Therefore I assume that you've ported your application from an older SQL Server version SQL Server 2012 Express.

    As Samuel already wrote, omit the size when creating the database to use the default size or specify a larger value than specified in the model database.

    As a side note - please look at the grow factory of the database and log file of the newly created database as the default as specified in model database are mostly stupid - initial size of 1MB for log and a grow factor of 10% are absolute stupid default settings.


    Please use Mark as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    Thursday, December 06, 2012 8:21 PM