How can I copy an SQL Server 2014 Express database to the same server without damaging original database [duplicate] - sql-server-2014-express

I would like to make a copy of a database I have but keep it on the same server as a test database. However, everything I have found is to use the copy database wizard (I am using MS SQL Server Express).
The instructions always say: In SQL Server Management Studio, in Object Explorer, expand Databases, right-click a database, point to Tasks, and then click Copy Database.
I don't have the Copy Database option. I am running as an admin, so no clue why it is missing for me - is it something I have to install separately? I can't do the Detach/Attach since it is copying to the same server. I tried detaching, copying the MDF/LDF, renaming, attaching but as you can imagine that messed a ton up :) I am not great with SQL to do it all programatically. Is there a tool out there I could use?

In SSMS 2008 you can do this:
Create a backup of the database you want to copy
In SSMS, right-click 'Databases' and select 'Restore Database'
Select the database you wish to copy from the 'From database' drop-down list in the 'Source for restore' section
Enter the name of the new database in the 'To database' field in the 'Destination for Restore' section - this cannot be the name of an existing database.
Click OK
You're done! :)

In SQL Server Express 2012 you can do following steps:
Create a backup of the database you want to copy
right-click "Databases" and select "Restore Files and Filegroups"
Enter the name of the new database in the "To database" field.
Select "From device" and then select the file that you backuped in the first step
click "OK"
this will "clone" the Database with the correct table settings such as the "default value" and "auto increase" etc.

SQL Express database has an export button, I just exported the database to a new database on the same server, it is copying the database. Just right-click on the database name.

Take these steps to make a copy of the database in SQL Express
Stop SQL
Copy the mdf, ldf and any other file for the db to a NEW location (make sure you get the log file)
Change the name of each copied file
Start SQL
Right-click Database in SSMQ and select attach
Make sure you change the name in the column "Attach As"
Update the file location in the lower pane of "Database Details" to the location of your copied files (especially that log file)
I was able to copy a database on my SQL Express system with this method

I had a problem creating a copy of my database as well using SQL Express 2012.
I have solved it by the backup and restore method.
After making the backup I used: restore -> files and file groups
Next step was to write a new name for the new database and set the source:
Pointing the source file
and finally, a overwrite the existing database with replace must be selected
and set names for new files with extension mdf and ldf that are different from the existing where is: Restore as
This method worked for me

Just be aware if you are using SQL Server Express 2012 of going to the option Files and make sure that the destination files (Restore As column) are different from the original files *.mdf and *.log
( I tried to put an image but need 10 reputation :p)

I do not believe the Express version of the manager will have the copy database feature. Have you considered copying via the backup and restore method?
http://msdn.microsoft.com/en-us/library/ms190436.aspx

I found the problem! Click on Databases, restore, then do the following:
After choosing from where to restore, and writing destination db name, go to files [annotation 1 on picture] and change the very right column files names to different than original [annotation 2 on picture] then it works :)

I just thought of a really nifty way to get around this :) So I thought I should post my idea. Note that this is 'untested' but I think it will work.
Do a "Back Up..." database (theoretically this is on your
production server, but it doesn't have to be)
Copy the backup file (from your prod server) onto your development machine
Assuming you're using SSMS Developer Edition on your development
machine, you can then do a "Restore" onto your development machine,
then do a "Copy Database" afterwards also on your development
machine (to create a new copy of the DB)
Now do a "Back Up..." on the new DB you just created, copy the backup file (to your production server) and do a "Restore" on the sql server express server :)
Hope this helps out a few people :)
Cheers,
Jeff

The solution is definitely to create a backup and restore it, but ensure that you're restored copy is pointing to different .mdf and .ldf files.
Here's how to check that using SSMS 2014 and a SQL Server 12 installation: assuming you're creating and restoring backups on your local disk.
Create a backup of your existing database
Right click the database, and choose "back up..." under "tasks."
(If you leave the location as the default, you don't have to hunt for the back up in the next step when you restore.)
Restore your backup to a NEW database:
Right click on databases, choose "restore database"
Select "device"
Click the ellipsis button ("...") to open the "Selct Backup devices" dialog.
Choose "File" as the backup media type and click the "add" button
Select the backup you just made, click ok (twice)
Now, back in the "restore database" dialog, type a new name for your destination database
Click "files" under "select a page" and make sure that "restore as" is pointing to .mdf and .ldf file names that do not already exist
Click ok!

I think you could try import data to a new database.
Create an empty database in your local sql server
Right click on the new database -> tasks -> import data
In the SQL Server Import and Export Wizard, select product env's servername as data source. And select your new database as the destination data.

As for the first part of your question (why do you not see this Copy Database Wizard option under Tasks for your dbs), the answer is indeed in the fact that you are running SQL Server Express. SQL Server Express doesn't support the SQL Server Agent feature, which this Copy DB feature relies upon, so the Copy DB feature is not shown (but many online resources fail to make that observation).
Fortunately, most everyone else has addressed the second part of your question (how to achieve the task otherwise), and nearly all point out using the existing backup and restore options (which DO exist in Express), or the export/import (which also exists in Express, I can confirm).

Try making a backup of your database, and restoring it into a brand new database.
Create new DB.
Make a full backup of your original.
Right click on your new DB, hit restore.
Navigate to your .BAK, and ensure the .mdf and .ldf match the new.

Related

Why does my databases folder show loading...?

I put a database in my databases folder (in assets) earlier and I could see it.
After updating Android Studio, when I click on the databases folder, it just shows "loading..." and it never goes away. I cannot see any file names.
I would not care except I updated my database and tried to copy it in again and it does not do anything.
(I copy the database and paste it in the folder. The pop-up to name the file comes up. I hit OK and the database does not change. Also, it still says "loading...")
Just fixed it. I had to disable SQLite plugin 1.4.1

setup project for visual studio application using advanced installer with local db data is retrieved but not saved in db

I am using advanced installer (simple) to create the setup project of a GUI i am making in visual studio. upon installation, it is possible to read data from the databse i.e the records that are already added can be read but as i try to save data in databse that function is not working and the application stops working. i think that the connection string is right that is why iam able to read data from it but why cant i update data. plz help.
the databse is is service-based local database
This might happen if you have the database stored in the same install location as your application binaries. Usually that is a folder under Program Files.
You're application cannot write under this location when running as a standard user, and it should never write/store data in that location.
If you're not using the Application Data folder to store your database, I suggest you update your app to do so, this should solve your problem.

How to disable visualstudio.com stored project's multiple check-out?

I have a project stored in visualstudio.com. However when I have a file checked out, my colleagues can do the same. How can I disable that feature? I went to TEAM -> Team Project Settings -> Source Control in VS 2012 and disabled "Enable multiple check-out". However nothing seems to have changed. Do I need to do something else with that? Secondly, I read this but when I right click a file and chose "Check-out for edit", it only has "Unchanged" and "CheckIn" lock types but no "Check-out" which, as I understand, is the thing I need to chose. So, is there a way to make sure only one person can edit a file at one time?
What kind of workspace are you using? Make sure you're using a server workspace. If you're using a local workspace which is the default when you create a new workspace in VS 2012/TFS 2012, checkout locks are disabled. For more info on local and server workspaces:
Decide Between Using a Local or a Server Workspace.

How to update a database programmatically, so that the updated one is included when publishing?

I'm copying and updating data from another database to mine (programmatically), this works fine when debugging. It also remembers it between debugging sessions. However, when I publish the program, the original database is empty.
How do I make sure the updated one is included?
This is an SQLCE database by the way.
When you are debugging the compiler will copy your SqlCe database to the bin\debug folder and that's the one you will be using when your program is running.
So when you copy data while debugging it will not end up in the database that is a part of your project but in the one in the debug folder!
Using the following tool could help. This will allow you to script the data that's in your database to a sql script so you can run it in your publish environment.

Azure SQL Database Bacpac Local Restore

I've created a BACPAC backup of my Azure SQL Database using the "Export" option within the Azure Management Console.
Having downloaded this to my machine I'm a little stuck on how I can restore this to a local SQL Server instance. I came across the DacImportExportCli tool but couldn't find an example of a local restore.
Also if anyone has written a script that does this (so it can be scheduled) that would be awesome.
This can be done simply through SQL Server Management Studio 2012
Right click on the Connection > Databases node and select "Import Data-tier application..."
Select "Next" on the introduction step.
Browse, or connect to a storage account where backups are kept.
Try "SqlPackage.exe"
I needed to export a SQL Azure database and then import it into a local SQL 2008 R2 server (Note I am also using Visual Studio 2010). Microsoft certainly went out of their way to make this a painful task, however, I was able to do it by doing the following:
Go to this link http://msdn.microsoft.com/en-us/jj650014 and install the SQL Server Data Tools for Visual Studio 2010
This will install on your local drive. In my case here is where it put it: C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin
Browse to this via the command line or powershell
You are going to want to execute the SqlPackage.exe
Open up this link to see a list of all the parameter options for SqlPackage.exe (http://msdn.microsoft.com/en-us/library/hh550080(v=vs.103).aspx)
Here is my command line that I needed to execute to import a .bacpac file into my local SQL 2008 R2 server:
.\SqlPackage.exe /a:Import /sf:C:\mydatabasefile.bacpac /tdn:NorthWind /tsn:BINGBONG
/tdn is the name of the database you want your bacpac file to restore to.
/tsn is the name of your SQL server.
You can see all these parameter descriptions on the link from #5.
You can restore the BACPAC by using the client side tools. Videos are here:
http://dacguy.wordpress.com/2011/09/09/importexport-services/
The tools are available here:
http://sqldacexamples.codeplex.com/documentation
Seems my prayers were answered. Redgate launched their SQL Azure Backup tool for FREE today - http://www.red-gate.com/products/dba/sql-azure-backup/download
If you're using SSMS 2012, it is as easy as right-clicking on the Databases folder under a server in the Object Explorer and choosing "Import Data-tier Application...".
There is one bump in the road to watch out for: as of Mar 26 2013 (when I needed to find out how to do this myself), when you export a .bacpac from Azure, it will be downloaded as a .zip file, not a .bacpac file, and the file dialog that is opened by the Browse button in the import wizard will only show either *.bacpac or *.* in the file filters, implying that .zip is not supported. However, if you change the filter to *.*, select your downloaded .zip, and click Next, the wizard will proceed normally.
Here's a script to restore a bunch of bacpac files at once:
Bulk Restore bacpac files local
cd [FOLDERPATH]
$goodlist = dir
cd 'C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin'
foreach($i in $goodlist){
$name = $i.Name;
$namer = $i.Name.Substring(0, $i.Name.length - 7);
.\SqlPackage.exe /a:Import /sf:[FOLDERPATH]\$name /tdn:$namer /tsn:[SERVERNAME]
}

Resources