DB Files reversed on deploymentHello,<br/><br/>I've been using VS2008 with the latest GDR R2 to create a SQL 2008 database.  I've been testing deployment and have noticed an issue.  I have 2 file groups (Primary and Staging). So under Schema Objects\Database Level Objects\Storate\Files I have 5 files:<br/>log.sqlfile.sql<br/>Primary_1a.sqlfile.sql<br/>Primary_1b.sqlfile.sql<br/>Staging_1a.sqlfile.sql<br/>Staging_1b.sqlfile.sql<br/><br/><br/>Primary_1a.sqlfile.sql code:<span style="color:#008000;font-size:x-small"><span style="color:#008000;font-size:x-small">  <pre lang=x-sql>-- Do not change the database name. -- It will be properly coded for build and deployment -- This is using sqlcmd variable substitution ALTER DATABASE [$(DatabaseName)] ADD FILE ( NAME = [$(DatabaseName)_1a], FILENAME = '$(DefaultDataPath)$(DatabaseName)_1a.mdf', SIZE = 6500 MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5 MB ) TO FILEGROUP [PRIMARY];</pre> <font size=2 color="#008000"><font size=2 color="#008000"> <p> </p> </font></font></span><font size=2 color="#008000"> <p> </p> </font></span> <p> </p> <p> </p> Primary_1b.sqlfile.sql code:<br/> <p> </p> <span style="color:#008000;font-size:x-small"><span style="color:#008000;font-size:x-small"> <pre lang=x-sql>-- Do not change the database name. -- It will be properly coded for build and deployment -- This is using sqlcmd variable substitution ALTER DATABASE [$(DatabaseName)] ADD FILE ( NAME = [$(DatabaseName)_1b], FILENAME = '$(DefaultDataPath)$(DatabaseName)_1b.ndf', SIZE = 6500 MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5 MB ) TO FILEGROUP [PRIMARY];</pre> <font size=2 color="#008000"><font size=2 color="#008000"> <p> </p> </font></font></span><font size=2 color="#008000"> <p> </p> </font></span> <p><span style="font-size:x-small">The problem occurs when I deploy, the first file is actually the Primary_1b.ndf not Primary_1a.mdf.  I discovered this when I did a detach database and then tried to attach the database again, it gave me an error that Primary_1a.mdf was not the correct file while Primary_1b.ndf was.  I did a new deployment straight from VS2008 and this occurs everytime, but I do see any option to set it.<br/><br/>Any ideas?<br/><br/>Thanks,<br/><br/>--Aaron</span></p>© 2009 Microsoft Corporation. All rights reserved.Sat, 04 Jul 2009 18:40:27 Ze99f2cd7-d226-4a12-b6d8-198725e445a1http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#e99f2cd7-d226-4a12-b6d8-198725e445a1http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#e99f2cd7-d226-4a12-b6d8-198725e445a1Vendoranhttp://social.msdn.microsoft.com/Profile/en-US/?user=VendoranDB Files reversed on deploymentHello,<br/><br/>I've been using VS2008 with the latest GDR R2 to create a SQL 2008 database.  I've been testing deployment and have noticed an issue.  I have 2 file groups (Primary and Staging). So under Schema Objects\Database Level Objects\Storate\Files I have 5 files:<br/>log.sqlfile.sql<br/>Primary_1a.sqlfile.sql<br/>Primary_1b.sqlfile.sql<br/>Staging_1a.sqlfile.sql<br/>Staging_1b.sqlfile.sql<br/><br/><br/>Primary_1a.sqlfile.sql code:<span style="color:#008000;font-size:x-small"><span style="color:#008000;font-size:x-small">  <pre lang=x-sql>-- Do not change the database name. -- It will be properly coded for build and deployment -- This is using sqlcmd variable substitution ALTER DATABASE [$(DatabaseName)] ADD FILE ( NAME = [$(DatabaseName)_1a], FILENAME = '$(DefaultDataPath)$(DatabaseName)_1a.mdf', SIZE = 6500 MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5 MB ) TO FILEGROUP [PRIMARY];</pre> <font size=2 color="#008000"><font size=2 color="#008000"> <p> </p> </font></font></span><font size=2 color="#008000"> <p> </p> </font></span> <p> </p> <p> </p> Primary_1b.sqlfile.sql code:<br/> <p> </p> <span style="color:#008000;font-size:x-small"><span style="color:#008000;font-size:x-small"> <pre lang=x-sql>-- Do not change the database name. -- It will be properly coded for build and deployment -- This is using sqlcmd variable substitution ALTER DATABASE [$(DatabaseName)] ADD FILE ( NAME = [$(DatabaseName)_1b], FILENAME = '$(DefaultDataPath)$(DatabaseName)_1b.ndf', SIZE = 6500 MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5 MB ) TO FILEGROUP [PRIMARY];</pre> <font size=2 color="#008000"><font size=2 color="#008000"> <p> </p> </font></font></span><font size=2 color="#008000"> <p> </p> </font></span> <p><span style="font-size:x-small">The problem occurs when I deploy, the first file is actually the Primary_1b.ndf not Primary_1a.mdf.  I discovered this when I did a detach database and then tried to attach the database again, it gave me an error that Primary_1a.mdf was not the correct file while Primary_1b.ndf was.  I did a new deployment straight from VS2008 and this occurs everytime, but I do see any option to set it.<br/><br/>Any ideas?<br/><br/>Thanks,<br/><br/>--Aaron</span></p>Wed, 01 Jul 2009 18:37:43 Z2009-07-01T18:37:43Zhttp://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#d5e32436-b118-41ba-9f7c-ce7de5ac3804http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#d5e32436-b118-41ba-9f7c-ce7de5ac3804Gert Drapershttp://social.msdn.microsoft.com/Profile/en-US/?user=Gert%20DrapersDB Files reversed on deploymentThe order of creation is inside the deployment script, can you look in your sql\debug\&lt;project name&gt;.sql file and see what the ordering and commands are in the deployment file. Please post that piece.<br/><hr class="sig">GertD @ www.DBProj.com Wed, 01 Jul 2009 18:50:09 Z2009-07-01T18:50:09Zhttp://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#cf920ac9-be62-4d63-9878-d9fcb7e23569http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#cf920ac9-be62-4d63-9878-d9fcb7e23569Gert Drapershttp://social.msdn.microsoft.com/Profile/en-US/?user=Gert%20DrapersDB Files reversed on deploymentI am already able to repro this, the result is:<br/><br/> <pre lang=x-sql>CREATE DATABASE [$(DatabaseName)] ON PRIMARY(NAME = [$(DatabaseName)_1b], FILENAME = '$(DefaultDataPath)$(DatabaseName)_1b.ndf', MAXSIZE = UNLIMITED, FILEGROWTH = 5 MB), PRIMARY(NAME = [$(DatabaseName)_1a], FILENAME = '$(DefaultDataPath)$(DatabaseName)_1a.mdf', MAXSIZE = UNLIMITED, FILEGROWTH = 5 MB) COLLATE SQL_Latin1_General_CP1_CS_AS GO</pre> I am not sure why the order is picked this way. As far as I know this does not change the way the database file work, they are both part of the PRIMARY filegroup, am I missing something? <br/><br/>SSMS displays based on file_id:<br/><br/> <pre>1 23B0932A-D9C2-4A16-8C00-F45AC2A93278 0 ROWS 1 gftest_1b d:\dbs\MSSQL10.MSSQLSERVER\MSSQL\DATA\gftest_1b.ndf 2 BF1947BF-A5E8-458C-882B-A487290FFC40 1 LOG 0 gftest_log d:\dbs\MSSQL10.MSSQLSERVER\MSSQL\DATA\gftest_log.LDF 3 AF640BBE-8C67-4028-B0F9-5D5F055B57F5 0 ROWS 1 gftest_1a d:\dbs\MSSQL10.MSSQLSERVER\MSSQL\DATA\gftest_1a.mdf</pre><hr class="sig">GertD @ www.DBProj.com Wed, 01 Jul 2009 19:05:45 Z2009-07-01T19:05:45Zhttp://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#6eab90e6-5329-4246-9080-401f091c8fb8http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#6eab90e6-5329-4246-9080-401f091c8fb8Vendoranhttp://social.msdn.microsoft.com/Profile/en-US/?user=VendoranDB Files reversed on deployment<p>Essentially there is no issue from a functional standpoint (i.e., it works properly and they are both part of the primary filegroup) and yes I understand that names and extensions don't matter when it comes to SQL Server databases.  <br/><br/>My concern was more along the lines of some future time when someone gets confused and wants to &quot;talk&quot; to me. :)  <br/><br/>But if there's no workaround/fix other than manually changing the names after deployment via detach/attach, then it's not a huge deal, but thought I'd see.<br/><br/>Thanks,<br/><br/>--Aaron<br/></p>Wed, 01 Jul 2009 19:43:26 Z2009-07-01T19:43:26Zhttp://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#089156c4-feaa-4f28-af08-b431f82cdde9http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#089156c4-feaa-4f28-af08-b431f82cdde9Gert Drapershttp://social.msdn.microsoft.com/Profile/en-US/?user=Gert%20DrapersDB Files reversed on deploymentThe developer off this provided the logic and reasoning behind this.<br/><br/>They choose the largest file first, this was because of a bug where if they choose the smallest one the content of model would not fit on a new database creation.<br/><br/>Sure enough when I use MDF size 11 and NDF of 10MB for example I get what you expected.<br/><br/> <pre lang=x-sql>ALTER DATABASE [$(DatabaseName)] ADD FILE ( NAME = [$(DatabaseName)_1a], FILENAME = '$(DefaultDataPath)$(DatabaseName)_1a.mdf', SIZE = 11 MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5 MB ) ALTER DATABASE [$(DatabaseName)] ADD FILE ( NAME = [$(DatabaseName)_1b], FILENAME = '$(DefaultDataPath)$(DatabaseName)_1b.ndf', SIZE = 10 MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5 MB ) CREATE DATABASE [$(DatabaseName)] ON PRIMARY(NAME = [$(DatabaseName)_1a], FILENAME = '$(DefaultDataPath)$(DatabaseName)_1a.mdf', SIZE = 11 MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5 MB), PRIMARY(NAME = [$(DatabaseName)_1b], FILENAME = '$(DefaultDataPath)$(DatabaseName)_1b.ndf', SIZE = 10 MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5 MB) COLLATE SQL_Latin1_General_CP1_CS_AS GO</pre> At least we know it was expected.<hr class="sig">GertD @ www.DBProj.com Wed, 01 Jul 2009 22:56:47 Z2009-07-01T22:56:47Zhttp://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#1ce38cd0-11a6-47c9-a23b-c04c93e5d555http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#1ce38cd0-11a6-47c9-a23b-c04c93e5d555Vendoranhttp://social.msdn.microsoft.com/Profile/en-US/?user=VendoranDB Files reversed on deploymentThat makes sense, however in my example above and your repro the files were identical in size so I wonder why it would be consistently choosiing the second file.  However now I know there's a workaround at least. :)  <br/><br/>Thanks,<br/><br/>--AaronThu, 02 Jul 2009 11:38:45 Z2009-07-02T11:38:45Zhttp://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#8e1a3165-f10b-4142-be40-b88f0149ff86http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/e99f2cd7-d226-4a12-b6d8-198725e445a1#8e1a3165-f10b-4142-be40-b88f0149ff86Gert Drapershttp://social.msdn.microsoft.com/Profile/en-US/?user=Gert%20DrapersDB Files reversed on deploymentIf you look closely the size is 11 and 10 MB, they are not the same.<br/><hr class="sig">GertD @ www.DBProj.com Thu, 02 Jul 2009 21:38:44 Z2009-07-02T21:38:44Z