I was working on a project where i made a database on sql server 2008 using visual studio 2010 and i took backup of that databse by right clicking on it in sever explorer and selecting "Publish to Provider" that creates a .sql file in my computer that i taken. Previously i formatted my pc and sql server databases are lost, so now i want to use that .sql file to recreate the database with all data, but i don't know how it can be possible.

Something i tried but it created all tables in master database but i want the database of the name i.e. stored in .sql file or specified by me.

Please help.

share|improve this question

feedback

2 Answers

up vote 2 down vote accepted

First Create a Database using this,

Create Database YOURDBNAME

Here, YOURDBNAME = DataBase Name

Then, Open your .sql file write this in First line of the .sql page,

Use YOURDBNAME

Now press F5, all the tables and data will be created and inserted.

share|improve this answer
thanx that worked well – user1306589 Aug 8 at 13:09
but in output it shown this (1 row(s) affected) for many times, do this shows i lost some data please reply. – user1306589 Aug 8 at 13:11
that message is the conformation for the rows that are inserted in tables. – SuganR Aug 8 at 13:17
thanx @SuganR.. – user1306589 Aug 9 at 14:34
feedback

You can use the SQL Server Management Objects libraries to manage all aspects of SQL Server.

SQL Server Management Objects (SMO) is a collection of objects that are designed for programming all aspects of managing Microsoft SQL Server. SQL Server Replication Management Objects (RMO) is a collection of objects that encapsulates SQL Server replication management.


From your description, however, this can be overkill. You get simply use SQL Server Management Studio (link goes to the free Express edition download), connect to the server, open a new Query Window with your SQL file and run it (F5).

share|improve this answer
but how???????? – user1306589 Aug 8 at 12:51
Is it possible to do the same using command prompt or Visual Studio. Because i have very slow internet connection and that SSMS file will take atleast 5 hours to me to download. If possible please tell me other ways using Visual Studio 2010. – user1306589 Aug 8 at 12:59
@user1306589 - Not sure this will work, but if you use the Server Explorer and open a new query on the server you need, you may be able to paste the SQL into the Query portion and run it. – Oded Aug 8 at 13:04
feedback

Your Answer

 
or
required, but never shown
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.