Originally, I created my database using SQL Server Management Studio on my local machine.
I now want to copy it into my App_Data in my web site folder, and in this way I hope to move my web site freely, meanwhile moving my database which contained in my App_Data to the other machine.
What steps should I follow?
I'm using SQL Server 2008 Express.
There are many way to transfer running database.
Using backup restore. refer microsoft
Using Replication.
Detach and Attach is not the right way because there is chance of data loss.
There are many ways to move/copy a database from one server to another server using SQL Server Tools.
i) Detach the database from the old server and attach it in the new server. This is purely offline operation and it moves the database instead of copying it.
Refer http://msdn.microsoft.com/en-us/library/ms190209.aspx : how to use attach/detach database in SQL Server Management Studio(SSMS)
ii) Back up the database in the old server and restore it in the destination server. This can be performed during online and it creates a new database in the destination server.
Refer http://msdn.microsoft.com/en-us/library/ms187048.aspx for more information.
iii) Using copy database wizard in SQL Server Management Studio.
Select the database in the source server in SSMS
Right click ->Tasks->Copy Database Wizard to launch the copy database wizard.
Enter the source and destination credentials and select either attach/detach or SMO type
click next and you can schedule or run immediately
Click finish to execute it
Refer http://msdn.microsoft.com/en-us/library/ms188664.aspx for more information.
iv) The last type is to generate the create script using Generate Script Wizard (SSMS) and execute it in the destination server.
Select the database in the source server in SSMS
Right click ->Tasks->Generate Scripts Wizard to launch the wizard.
Select the various scripting options needed and select the objects needed to generate the scripts for them. Make sure script data = true in the scripting option to generate script for data as well (INSERT statements)
click next ->next and finish to generate the script (new query window or clip board or file)
connect to the destination server and create the new database in it.
Click new query window and paste the script generated using GSW above and execute them with the destination database context.
Refer http://msdn.microsoft.com/en-us/library/ms181421.aspx for more information
v) Using Transfer Object in SMO
Sample code:
ScriptingOptions so = new ScriptingOptions();
so.ScriptData = true;
Transfer t = new Transfer(db);
t.CopyAllObjets = true;
t.options = so;
...................
..................
t.TransferData();
Note: Transfer class is available in Microsoft.SqlServer.SmoExtendedClass.dll (SQL Server 2008)
or Microsoft.SqlServer.Smo.dll (SQL Server 2005)
There are various member variables to be configurable. Also ScriptingOptions class object can be created and assigned to the transfer object as well.
set ScriptData = true in order to transfer data also. It copies the destination instead of moving the database
Refer http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.transfer.aspx for more information.
vi) You can make use of Database Publishing Wizard to accomplish this. You can specify the target version as SQL 2005 or SQL 2000 etc as per your requirement.
Related
I'm using forms authentication to handle users and attempting to deploy my database to SQL Azure, but getting this error message:
The only table of the four listed that I utilize is aspnet_Membership, and the only other table I use is aspnet_Users from implementing forms authentication. What is TextInRowSize and why does SQL Azure care about it? Do I have any option to modify aspnet_Membership to make it compatible?
If it would be easier to remove the current system altogether and replace it with my own, I'm fine with that too.
That looks like an error in the data-tier application framework. I can suggest a workaround to get your database to Azure:
Use SqlPackage.exe (https://msdn.microsoft.com/en-us/library/hh550080(v=vs.103).aspx) from the command line to extract a dacpac file with all table data. Then use SqlPackage.exe to deploy that dacpac file to your database in Azure. The extract command would look something like:
C:\>"c:\Program Files\Microsoft SQL Server\120\DAC\bin\SqlPackage.exe" /a:extract /scs:"Data Source=yourSqlServer;Integrated Security=true;Initial Catalog=yourDatabase" /tf:C:\temp\mydatabase.dacpac /p:ExtractAllTableData=true
And the import command would look something like:
C:\>"c:\Program Files\Microsoft SQL Server\120\DAC\bin\SqlPackage.exe" /a:publish /tcs:"Data Source=yourAzureSQLServer.database.windows.net;User Id=yourUserId;Password=yourPassword;Initial Catalog=yourDatabase" /sf:C:\temp\mydatabase.dacpac
So quick suggestions since I see you are using V12 which should support those properties now.
First make sure you are using SSMS 2014 SP1 at least, this has a number of fixes for using V12. Secondly make sure you install the May 2015 update to DacFX (which is the program that creates bacpac files) you can install it here: http://www.microsoft.com/en-us/download/details.aspx?id=46898
This should get you to the best possible chance of your import/export working.
This was solved by generating a SQL Azure script for the DB, and running it on Azure. Here's how I solved it:
First, open SQL Server, right click the database you want to transfer and click "Tasks > Generate Scripts..."
Next, click "Advanced" on the scripting options panel and find the row "Script for the database engine type." Select "Windows Azure SQL Database" and click OK (Note: if you have data that you want to transfer as well, choose "Schema and Data" from the "Types of data to script" option).
Proceed thru the rest of the script generation dialog, remembering where you saved the script file. Connect to your database server using SQL Server or windowsazure.com. Generate a new query for your new database, enter the script that was generated by SQL Server and execute.
Seems like TextInRowSize stores large data for older SQL Server types such as text and ntext. You would need to change it's type to nvarchar(max).
Here's a link to a more detailed explanation.
http://www.dnnsoftware.com/wiki/unsupported-property-textinrowsize-set-and-is-not-supported-when-used-as-part-of-a-data-package
I created a .bak file (backup) from server A with the with following specs: Windows server 2003, MSSQL 2005. Now I would like to restore this backup on a new Server B with the following specs: Windows 8, MSSQL 2008 R2. I did the following to try and do the restore
Copy files to the new server(Server B)
Clicked on Microsoft SQL Server Management Studio 2008R2(Server B)
Right click on Databases to create a new Database called Boom (Server B)
After creating the new Database(Boom), right clicked on Tasks->Restore->Database and
On the source for restore area, Clicked From device and located the .bak file, select it and cliked ok.
Instead of getting the success message, I get the following error:
Restore failed for Server 'Server B'.(Microsft.SqlServer.SmoExtended)
Additional information: System.Data.SqlError: The backup set holds a backup of a database other than the existing 'Boom' database(Microsoft.SqlServer.Smo).
Please assist, Im am new to MSSQL
Right click on Databases to create a new Database called Boom (Server B)
After creating the new Database(Boom), right clicked on Tasks->Restore->Database and
Well now you're making a new database and trying to overwrite it with a different database's backup. Hence:
The backup set holds a backup of a database other than the existing 'Boom' database
There's a WITH REPLACE option that allows you to proceed, but just avoid the indirection to begin with: restore the database, don't make a new one.
You'll probably need to delete the redundant Boom database you made, first. If, for whatever reason, you couldn't delete the database you'd have to use WITH REPLACE.
"Restore failed for Server 'Server B'.(Microsft.SqlServer.SmoExtended) Additional information: System.Data.SqlError: The backup set holds a backup of a database other than the existing 'Boom' database(Microsoft.SqlServer.Smo)."
I encountered this error when the logical name of the files do not match. Check on the logical name of the database you backed up and you will need the same logical name for the new database you created.
Or you can surely use the With Replace option too as specified by ta
I am very new to database and programming.
I have created database on one PC. Now I need to get a copy of same DB and have it on my PC(including the tables and its data).
I have SQL Server 2005.
When I try to export the database it will ask for another machine.
Please provide me guidance or beginners level example link
There are plenty of ways to do this, but I'm a huge proponent of BACKUP and RESTORE.
Create a folder called c:\temp\ and give EVERYONE full control. Open a query window in SSMS.
BACKUP DATABASE database_name
TO DISK = 'C:\temp\database_name.BAK' WITH INIT;
Also run the following to determine the logical filenames:
USE database_name;
GO
EXEC sp_helpfile;
Now copy the file to the other machine (in a folder also called c:\temp). And in a query window on that instance:
RESTORE DATABASE database_name
FROM DISK = 'C:\temp\database_name.BAK'
WITH REPLACE, RECOVERY,
MOVE 'data file name' TO '...path...\database.mdf',
MOVE 'log file name' TO '...path...\database.ldf';
You'll need to replace some variables there but hopefully that provides the gist.
You can backup and restore the database.
Another method is to go to SQL Server Management studio and script out all objects in the database.
On the advanced tab, you can choose to have it script out the data in tables too.
To get to the wizard, right click on the database, choose "Generate Scripts", and follow the instructions in the wizard.
Then, you can save it out as a file. Or, you can just paste it into a SSMS window connected to the other database and run it.
You would not do this for a database that has any significant amount of data.
Best way to do this is to Backup and Restore like Aaron already suggested but here is another thing you can try.
Stop SQL Server services. (Go to SQL Server Configuration manager -> SQL Server Services -> Right click SQL Server service and click stop)
Go to SQL Server data folder (Right click on the database -> Properties -> Files)
Copy MDF and LDF files to another computer
Start the SQL Server services again from the SQL Server Configuration Manager
On target machine open SQL Server Management Studio, right click on the Databases folder and click Attach and select MDF and LDF files you copied.
this will help u...
go to your database,select database which you want to use on other pc,right click on it go to task->select detach,then it will show database name then click OK.
After this its .log and .mdf file goes to c:/program files/Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA .here you will find your database name 2 files ,from this you copy it and past it where you want it.you can get database on another pc .
Is there a feature in sql server 2008 management studio to generate database create scripts from existing database without data and with all the relationships maintained.
Yes, of course.
Go into: Tasks > Generate Scripts Then,
in Choose Script Options set Scrpit Data = False (default)
In SSMS, right click the db and select "Script database as Create to"... whatever you want
I need to export database from one server and import it into another server.
How do I export the entire database to a file, or two files mdf, ldf (either option is fine)
How do I import it into a new server using ssms?
In the instructinos frmo ponies, it says:
In the To a point in time text box,
either retain the default (Most recent
possible) or select a specific date
and time by clicking the browse
button, which opens the Point in Time
Restore dialog box. For more
information, see How to: Restore to a
Point in Time (SQL Server Management
Studio).
To specify the source and location of the backup sets to restore, click
one of the following options:
From database
Enter a database name in the list box.
I am unable to type anything in restore
https://stackoverflow.com/questions/3241108/i-backed-up-the-database-in-ssms-sql-server-how-do-i-restore-it
Using SQL Server Management Studio, you use Backup/Restore feature. The Restore process is laid out in the MSDN documentation. And here's the MSDN article for backing up a database...
Obviously, you restore to another SQL Server database instance (a "database instance" can contain multiple databases.). The version of the instance can be newer than the version the backup came from - the compatibility level will just be set accordingly.
If you want to generate a .sql file:
right click on the database in SQL Server Management Studio
select Tasks->Generate Scripts... .
In the dialog that pops up, Select All on the screen that says "Select database objects to script"
The generated .sql file can be opened again in SQL Server Management Studio and be run. If the .sql file is very large, see How do you import a large MS SQL .sql file?
If you want to export / save all data of a database into a .sql file, do this:
Right click on the database in SQL Server Management Studio
Tasks -> Generate Scripts
Script entire database and all database objects
Next
Click - Advanced
Scroll down to Types of data to script and set from Schema only -> Schema and data -> Ok
Save as script file (name it and save it where you want it)
Next
Next
Done ✔️
You can open the file now and see that all values are also included now
The best way to do this is to backup the database. This will backup to one file. Then take that file to your new server and do a restore. This should restore everything, from tables to stored procedures to foreign keys and all the data.
Also, if you just want to move a database to a new server, Detach/Attach is a quicker option. Backup/Restore is what you want if you want to keep the original database in place.