Restore BacPac database backup in sql server 2014 - sql-server-2012

I have database backup file with extension .bacpac so how can i restore it in sql server 2014 ?

Two options:
In SQL Server Management Studio, right-click on the Databases folder in the Object Explorer tree. Then click on "Import Data-tier application". The wizard will guide you through the process.
From the command line, run this command: "c:\program files (x86)\Microsoft sql server\120\dac\bin\sqlpackage.exe" /a:import /sf:"PATH_TO_YOUR_BACPAC_FILE" /tcs:"Data Source=YOUR_SERVER_NAME;Initial Catalog=NEW_DATABASE_NAME;Integrated Security=true"
Aside: Note that the example connection string in the command line option above assumes you're using Windows Authentication instead of SQL Server authentication to access the server.

Related

SQL LocalDB - Cannot delete a DB when its files are deleted

How can I delete a SQL LocalDB database that has had its files delete?
Dropping the database yields this message:
Unable to open the physical file "C:\Users\Public\Documents\LocalDB.Tests.3d0d7339-7cf2-45fe-a83b-b5079112ab80.mdf". Operating system error 2: "2(The system cannot find the file specified.)".
File activation failure. The physical file name "C:\Users\Public\Documents\LocalDB.Tests.3d0d7339-7cf2-45fe-a83b-b5079112ab80_log.ldf" may be incorrect.
Running master.sp_databases actually doesn't show them, but the Management Studio does.
The problem is that you are trying to drop a database when the physical file has been deleted or couldn't be found.
To get around this you can detach the database. Detaching will drop the database without attempting to remove the file from the filesystem.
EXEC sp_detach_db 'My_Db'
I'm assuming you're using (localdb) bundled with SQL Server 2012.
If you're using SQL Server 2014, use (localdb)\MSSQLLocalDB in place of (localdb)\v11.0 below
Open a command prompt
Start the localDb instance if it is not already running: “C:\Program Files\Microsoft SQL Server\110\Tools\Binn\sqllocaldb.exe” start “v11.0″
Drop the localDb database by running the following command: “C:\Program Files\Microsoft SQL Server\110\Tools\Binn\sqlcmd” -S (localdb)\v11.0 -E -d master -Q “DROP DATABASE [myDatabase]”
You can stop the localDb service now: “C:\Program Files\Microsoft SQL Server\110\Tools\Binn\sqllocaldb.exe” stop “v11.0″
Source: http://kazimnami.azurewebsites.net/techblog/2013/02/27/delete-localdb-database-after-physical-files-have-been-deleted/

How to take SQL Server 2012 schema + data dump using command prompt

I have a database in SQL Server 2012. Now I am looking for some windows commands that will generate an .sql file for the schema[create statement] and another .sql file for the data[insert statement] of that database. I need to do this using command prompt. So I can't use the Generate Scripts option provided in SQL Server Management Studio.
Thanks in advance
The schema dump from command-line can be done using SQLPackage.exe. The command is -
"C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\sqlpackage.exe" /action:Extract /tf:<drive:\folder_name\file_name.dacpac> /SourceConnectionString:"Data Source=<server_name>;Initial Catalog=<db_name>;Integrated Security=SSPI;Persist Security Info=False; /su:<user_name> /sp=<password>
If using windows authentication then input username = password = space. The file paths that contain spaces must be enclosed in quotation marks.
See https://www.katieandemil.com/sqlpackage-exe-extract-dacpac-command-line?tab=article for more details.

Unable to connect to SQL Server 2008 R2

I am unable to connect to a local SQL Server 2008 R2 trial version from Visual Studio 2010 Express.
When adding a new connection, I browse to the database file in this location:C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\AdventureWorks_Data.mdf, I encounter this error:
Could not open new data base 'C:\PROGRAM FILES\MICROSOFT SQL
SERVER\MSSQL10_50.SQLEXPRESS\MSSQL\DATA
ADVENTUREWORKS_DATA.MDF'.CREATE DATABASE is aborted. An attempt to
attach an auto-named database for file C:\Program Files\Microsoft SQL
Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA AdventureWorks_Data.mdf
failed. A database with the same name exists, or specified file cannot
be opened, or it is located on UNC share. File activation failure.The
physical file name "C:\Program Files\Microsoft SQL
Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\AdventureWorks_Data_log.ldf"
may be incorrect.
The log cannot be rebuilt when the primary file is read-only.
Another guess, you don't by any random chance have another user logged into the same machine that would have the DB file locked by connecting to it in the same way you say you're trying to? I'd imagine the previous comment about that database file already being attached to by the sql service is probably far far more likely, but just for wild chance I'm leaving my idea here for you or anyone else who happens by

SQL Server 2008 installed, though running version is still 2005

A while back I installed SQL Server 2008 on a development machine which already had Sql Server 2005 express from Visual Studio. When I look in my programs, I see 'Microsoft Sql Server 2008', which contains the management studio, etc. As well I can see 'MS Sql Server 2005'.
When I run a query in Management Studio 2008 to select the version running on my machine, it comes up as 2005, and leaves me scratching my head. When I look in the configuration manager, all I see is the SQLEXPRESS instance running ...
Are there any "quick" solutions to get 2008 running instead of 2005, considering 2008 is installed?
If your using the SQL Server 2005 Configuration Manager you will only see 2005 instances and lower.
To view instances of SQL Server 2008 you will want to make sure you are using SQL Sever 2008 Configuration Manager.
The final option would be to View All services using the Service Control Manager. Here you will need to look at what instances of SQL Server you have running on the machine.
If you want to find all the instance names, one way is to run powershell and execute the following
PS C:\> gwmi win32_service -filter "name like 'MSSQL%'" | fl DisplayName, pathname
For me the result is
DisplayName : SQL Server (SQLEXPRESS)
pathname : "c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\B
inn\sqlservr.exe" -sSQLEXPRESS
DisplayName : SQL Server (SQLEXPRESS2005)
pathname : "c:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Binn\sqlserv
r.exe" -sSQLEXPRESS2005
DisplayName : SQL Full-text Filter Daemon Launcher (MSSQLSERVER)
pathname : "C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\
Binn\fdlauncher.exe" -s MSSQL10.MSSQLSERVER
DisplayName : SQL Server (MSSQLSERVER)
pathname : "C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\
Binn\sqlservr.exe" -sMSSQLSERVER
DisplayName : SQL Server Active Directory Helper
pathname : "c:\Program Files\Microsoft SQL Server\90\Shared\sqladhlp90.exe"
DisplayName : SQL Active Directory Helper Service
pathname : "C:\Program Files\Microsoft SQL Server\100\Shared\SQLADHLP.EXE"
DisplayName : SQL Server Analysis Services (MSSQLSERVER)
pathname : "C:\Program Files\Microsoft SQL Server\MSAS10.MSSQLSERVER\OLAP\bi
n\msmdsrv.exe" -s "C:\Program Files\Microsoft SQL Server\MSAS10.M
SSQLSERVER\OLAP\Config"
Look for the one that has MSSQL10 and make sure that the service is started. Then use that instance name when connecting via SSMS.
If for some reason you didn't install into the default structure you can always visit the Exe directly and check its version for something like 2007.100.xxx
I happen to have 2005 and 2008 express as well as 2008 standard
If I was better at PowerShell I would have piped the PathName to get the version info

SQL Server 2005 backup restore failing (with folder permissions)

I am trying to restore a database (from file thedb.bak). I am using SQL Server Express edition 2005 on a Windows 7 Ultimate 64-bit machine.
When I try to restore I get the following error:
System.Data.SqlClient.SqlError: The operating system returned the error '5(Access is denied.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL.2\MSSQL\Thedb.MDF'. (Microsoft.SqlServer.Express.Smo)
My username (antoniocs) is an Administrator. I have edited the permissions in the folder (C:\Program Files (x86)\Microsoft SQL Server\MSSQL.2\MSSQL\) so that the user AntonioCS has full control.
I really need to restore this backup. What am I missing?
Note: I am using the Windows authentication to login. Should I try another user (the one I use is an administrator in the machine)?
The account running the SQL Server service requires permissions on that folder.
You may be connected to SQL Server, but actions are done in the service account context: not you.
Run services.msc from command line, see what account is used, permission this folder accordingly.
Do you have a database that uses Thedb.MDF? I ran into this error when I tried to restore a database over a file that SQL Server used. From the restore window, choose Options and change the path or the filename from the "Restore the database files as".