Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm not sure if I should be asking this here or over at stackoverflow I apologize if it is the latter.

I have been developing an application in Visual Studio 2010 and using it's built in database functionality with a local .mdf file. I have recently gotten access to a SQL Server 2008 installation, but I can't figure out how to migrate the database.

I have gotten Visual Studio to create a SQL script that should migrate the data, but I can't figure out how to actually run it in SQL Server Management Studio.

Any ideas? Ideally I would like to migrate the schema and the data, but I can settle for just the schema.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

If you have an appropriate MDF and LDF file you should be able to attach them within Management Studio by right clicking on the databases folder under your server name in Object Explorer and selecting attach database. Alternatively you can use T-SQL to attach your database files - although you may find the GUI easier to do so.

This link will describe how to do so step by step: http://msdn.microsoft.com/en-us/library/ms190209.aspx

Alternatively to run the script Visual Studio gave you, if you right click on the server name and choose new query you can paste the script here and execute it (use F5 to execute) to run the script.

share|improve this answer
    
Thanks, I figured it was something stupidly easy, I had just never done it before. –  rybl Mar 3 '11 at 4:51
1  
You just need to make sure you have an appropriate LDF file to go with the MDF file. With out the LDF you cannot attach the database. Also make sure in your script, if you use this method, that it has a CREATE DATABASE command at the start. If not you will need to make sure you create a database and execute the query in that database. –  Ian Chamberland Mar 3 '11 at 5:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.