none
How do I install AdventureWorks2012 OLTP database from script?

    Question

  • I just installed SQL Server 2012.  But I cannot install this database either from script or from MDF file.  When I try to install it from script, I get the error:

    Loading [Person].[Address]
    Msg 4861, Level 16, State 1, Line 4
    Cannot bulk load because the file "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\Tools\Samples\AdventureWorks 2012 OLTP Script\Address.csv" could not be opened. Operating system error code 3(The system cannot find the path specified.).
    ** An error was encountered during execution of batch. Exiting.

    I commented this table out, but then I got errors on the tables after this.  Only part of this database was installed.  I checked and I do not see a Tools\Samples directory anywhere on my computer! 

    Next, I dropped this database and then I tried

    CREATE DATABASE AdventureWorks2012 ON (FILENAME = '{drive}:\{file path}\AdventureWorks2012_Data.mdf') FOR ATTACH_REBUILD_LOG;

    But this gave me an error:

    File activation failure. The physical file name "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\AdventureWorks2012_Log.ldf" may be incorrect.
    New log file 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\AdventureWorks2012_log.ldf' was created.
    Converting database 'AdventureWorks2012' from version 705 to the current version 706.
    Database 'AdventureWorks2012' running the upgrade step from version 705 to version 706.

    How can I install this database?  And yes, I followed the instructions here:

    http://social.technet.microsoft.com/wiki/contents/articles/3735.sql-server-samples-readme.aspx#Readme_for_Adventure_Works_Sample_Databases


    Ryan D


    • Edited by ironryan77 Saturday, July 06, 2013 5:25 AM
    Saturday, July 06, 2013 3:11 AM

Answers

All replies

  • Hi,

    Did you try to attach the database using SSMS?


    Thanks & Regards RAJUKIRAN L Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers.

    Saturday, July 06, 2013 7:53 AM
  • The last message that you got is not really an error.

    You are creating the database with only the data file and instructing SQL Server to rebuild the transaction log file.

    Since the file wasn't there, a new log file was created and then the database version was upgraded.

    You should be able to use the database now.

    HTH




    Pradeep Adiga
    Blog: sqldbadiaries.com
    Twitter: @PradeepAdiga

    Saturday, July 06, 2013 5:57 PM
  • your issue is in code where your  csv file located in you script


    :setvar SqlSamplesDatabasePath "C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\"
    -- NOTE: Change this path if you copied the script source to another path
    :setvar SqlSamplesSourceDataPath "C:\Program Files\Microsoft SQL Server\120\Tools\Samples\Adventure Works 2014 OLTP Script\"



    Vijay Patel

    Wednesday, May 25, 2016 7:55 PM