Azure SQL Database Bacpac Local Restore - azure

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]
}

Related

Is there Support .sql File in SharePoint?

I uploaded .sql file in sharepoint. Unfortunately; there is only a download option if I want to view it. Is there a way to maintain such files in Sharepoint other than in .txt file?
As I understand, .sql is struct Query Language Data file,so SharePoint not provide the default program to open .sql file.
If you are using MS SQL Server Database, you could download and install SQL Server Management Shell which supported to open .sql file:
Download SQL Server Management Studio (SSMS)

ssis importing to an other server

There is a SSIS project which takes data from oracle table and export that into xls file.But before exporting there are File System Task and Execute SQL Task which are supposed to delete xls file and after that create it again. The project looks like on images:
it perfectly works on a lochalhost. But the task is to export a file to other server. Excel file path for "Excel connection manager" is
C:\Users\YIskende\Desktop\New folder\report.xlsx
but how to change that in such a way to make it work with an external server
2 solutions (it depends also from SSIS and SQL Server version)
1) Package Deployment Mode: If you use a package configuration (old SSIS and SQL Server versions), you can create a Configuration database on your server where to store paths and variable values (Menu: SSIS -> Package Configurations)
2) Project Deployment Mode: In SQL Server 2014 version you have a Integration Services Catalogs in SQL Management Studio where deploy your project and save your values

Writing a flat file in SSIS succeeds if run from VisualStudio, fails if run from the Integration Services Catalog

I have an SSIS package that does a Bulk Insert, then executes a SQL Task, and then finally writes some database data to a flat file on our network. The package runs fine if I run it from Visual Studio 2012. However, if I deploy the package to the Integration Services Catalog on a 2012 SQL Server and run it from there, the Bulk Insert and SQL Task run fine, but when the package tries to output to the flat file, I get these error messages:
Cannot open the datafile "\\nyfil006\Projects\Accounting\CostRecovery\Cafe de Novo\HospitalityCharges.csv".
HospitalityCharges Flat File failed the pre-execute phase and returned error code 0xC020200E.
I'm able to output the System::UserName to an errorlog, and it's what I think it should be: an account that has full permissions to the folder in the flat file destination (and its parent folders). I've tried creating a blank version of HospitalityCharges.csv, and DelayValidation is set to True for the Data Flow Task that outputs the flat file. My system admin has granted Network Service permissions to the folder as per this link and this link, but that doesn't help. I've also made the connection string an expression as described here. We've also created a mapped drive and used that for the Destination Connection String instead of a UNC path. No joy. Does anyone know why this is happening?
Another note: if I change the flat file destination to point to the C: drive, the package runs fine, whether I run it from Visual Studio or from the Integration Services Catalog.

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

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.

How to connect to SQL database from Visual Studio/ open .mdf file

If I copy an .mdf file created by SQL server management studio and put it in the app_data folder I get this error:
"This database file is not compatible with the current instance of SQL Server.
To resolve this issue, you must upgrade the database file by creating a new data connection, or you must modify the existing connection to this database file.
For more information, see http://go.microsoft.com/fwlink/?LinkId=235986"
And if I attempt to Add connection using the visual studio wizard, choosing the Microsoft SQL server database file and select the file I get this error:
"
Unable to open physical file "path" {access is denied) an attempt to attach an auto named for file "path" a database with the same name exists, or specified file cannot be opened, or it is located on UNC share"
And if I attempt to add a connection choosing the "Microsoft SQL server" option in the choose data source window:
"a network related or instance specific error occurred while establishing a connection to SQL server. the server was not found or was not accessible. Verify the the instance name is correct and that the SQL is configured to allow remote connections..."
The only reason I want to connect visual studio to the database is because VS doesn't allow me to import text files. I have imported a text file into a DB from SQL server management studio and I want to connect it to VS. I've turned off UAC in windows 7 and I have file permissions to the mdf file.
Old question, but just to provide an answer for visitors from Google, the problem is not related to file system access (although Administrator accounts should have full privileges to the folder containing the mdf and log files). The solution is that SQL Management Studio needs to be opened using "Run As Administrator". The elevated permissions will allow SQL Server (or SQLExpress) to attach the older mdf file and update it. Once the db is attached, you can access it in Visual Studio by adding a database connection through the Add New Item->Data->ADO.NET Entity Data Model wizard.

Resources