How to unlock a Database.mdf file so can share with friends? - sql

Does anyone know how to unlock a SQL Server .mdf file so can share with friends?
Because the file that my friend share with me for our group assignment happen to be locked up and that I can't use the data within and only can view it.
Actually I want to share my database with my partner in this group assignment. We use a similar database. However, due to reason of time meet up with our instructor, we both need to have our own holding of a database for presentation at different time.
Also the reason, I want to learn to unlock it is because, we may need to try in on different hardware as well. Is in by Exporting? Like what is shown in this link video? https://www.youtube.com/watch?v=c2XmaCFk-kk

Firstly, to be able to use .mdf/.ldf files in common operations like Copy/Paste you need:
1. Under Sql Server Management Studio right click on the DB:
2. Then under Detach window check 'Delete Connexions' and click Ok:
You're free to do whatever you want with your .mdf/.ldf files

You probably shouldn't be sharing the MDF files, but if that's what you want to do you will indeed have to detach the database and transfer MDF and LDF files before attaching it on the other side.
It's not completely clear what you want to accomplish, but I think your best option is to take a backup on your machine, transfer the backup to the other machine and restore it there, that way the database doesn't have to go offline.
See this link for a how-to on the backup/restore method.
See this link for instructions on the detach/attach method

Share SQL connection, not the MDF file. Use SQL Surface to enable network access to your DB and define user logins.

Related

"Logical file 'Movies' is not part of database"

First and foremost, I am very brand new to databases so please keep instructions simple for me. thanks!
Usually when I need to make a manual change I just back up my SQL Server Management Studio 2012 database called Movies, then upload it to my host, then use their restore feature to implement it.
I am still in a testing phase so data does not need to be kept that is acquired online, however I wanted to try keeping the data today so I used the host's backup option which created a DB_76779_test_backup.bak file for me.
I then download this and "attempted" to updated it's information into the SQL database on my machine (Movie) which I believe is where I messed everything up.
From what I remember I right-clicked my database "Movies" and selected "Tasks -> Restore -> Database", I kept everything as is, but for Source I selected Device then chose the DB_76779_test_backup.bak file and and below that selected "Movies" as the Database and hit OK.
This seemed to work fine, so I opened and edited the tables values that needed to be changed. Then as usual, I just backed it up, ftp'ed it to the host, and restored my database.
I got an error however when trying to restore and my support told me the following.
"Logical file 'Movies' is not part of database 'DB_76779_test'. Use
RESTORE FILELISTONLY to list the logical file names."
I'm afraid we only support restores of databases that contain only 1
.mdf file and 1 .ldf file with no extra partitions.
I am assuming that since the only different thing I did this time was restore my database on my computer is that somehow I broke it, or created more than 1 mdf and ldf file (no clue what those even are). All I was trying to do was keep the actual data from online, so I am not even sure if that was correct way to go about this, but regardless I am unable to restore the database on my host now..
I am hoping someone here has instantly realized what idiotic mistake I made, because I only know a basic level of databasing and not much of the "under the hood" mechanics.
Let me know if you need further details.
That SSMS dialog is a little difficult to work with some times. It looks like you want to rename your database to Movies. The problem is when you change the name field it does not update the logical names it is using for the files. IIRC simply switching to the Files "tab" on the left will update it and then you can restore fine. That or do your restore with the "old" name and then name the database after restore.

Saving and accessing SQL databases in Azure?

A friend of mine has 3 small SQL databases on her Azure account that she asked me to download for her. I said no problem…thinking she had a VM running with SQL Server and I could just RDC in and grab everything…no such luck and no FTP access.
I've done an export but have no idea how to download the .bacpac file.
I've logged in through the management portal - but there's no options in there to export/download anything.
Can someone tell me the best - easiest - way to save these databases? Is there an easy way to download them? If I configure a VM in her account can access them that way? Is there a way I can transfer them over to my account?
I don't know all that much about Blob storage and container management - I've seen a few instructions and they seem very complex to me just to download a .bacpac file so I'm assuming I'm missing something.
Any help or ideas would be great!
Thank you...
Rob
Here is a solution to your problem.
Use a linked server connection between your on premise database and SQL AZURE.
http://blogs.msdn.com/b/windowsazure/archive/2012/09/19/announcing-updates-to-windows-azure-sql-database.aspx
Quick list of steps.
1 - Link to SQL Azure database.
2 - Script out objects.
http://craftydba.com/?p=4827
Check out how to manage Azure from SSMS on my blog. Half way down, right click table, script as Create.
http://blogs.msdn.com/b/sqlazure/archive/2010/05/24/10014071.aspx
How to script a whole database.
3 - Create mirror database on premise using scripts from step 2.
4 - Create linked server to AZURE database.
http://msdn.microsoft.com/en-us/library/aa560998.aspx
5 - INSERT INTO SELECT * FROM
http://technet.microsoft.com/en-us/library/ms174335.aspx
Why select * into does not work in Azure. Might work with a linked server. Never tried.
http://blogs.msdn.com/b/windowsazure/archive/2010/05/04/select-into-with-sql-azure.aspx
6 - Watch out for constraints such as primary key on identity column. You will have to enable identity insert. Other constraints, you can disable.
7 - Re-enable constraints with checking.
Again, this whole process assumes you do not have a ton of data. If you do, you might want to look into using a ETL tool such as SSIS.
You can mount the Azure Page Blob as an NTFS drive using a utility like XDrive. I'm trying to use "Azure Storage Explorer" to do the same thing but it's not allowing me access to the files inside of the VHDS file (and I think that it should). XDrive is supposed to allow for a mapped drive type feel in Windows Explorer.
Backup the databases to the secondary hard drive on the Vm's. Download, install, and configure XDrive to point to this hard drive. Grab the backups. Voila! Please note that XDrive limits read/write access to distributed enviornments so this should only be used as a tempory solution for environments not distributed (ie. load balanced) or you could cause a disruption to your production users.
XDrive: http://blog.maartenballiauw.be/post/2010/02/02/Using-Windows-Azure-Drive-%28aka-X-Drive%29.aspx
Updated:
Download "Azure Storage Explorer" from http://azurestorageexplorer.codeplex.com/
From the Azure portal, click on the db you want to export and from the dashboard tab, there's an "Export" button. This will create a bacpac file.
Choose a storage account (remember which one you chose because you will have to access it later).
For the container, create a new one called "DB Storage" or something like that. You will need to server credentials to do the export.
After the export completes, open up "Azure Storage Explorer" and add the storage account you placed the backup in. You will need the storage account name and the primary key (both can be pulled from the Azure portal). I have to use the option "HTTPS" but you may or may not.
Once the account is in the explorer, on the left pane you should see the new container you created in the earlier step. Click on it which should pull up your bacpac file in the middle pane.
Highlight the bacpac file and choose download.
It's a bit of a pain because you have to install the explorer utility but after that's done, it's really easy.
Let me know if this works.

Taking a SQL Database with me for a presentation

I am a beginner with sql and tomorrow I have to turn in my first assignment, which is a simple, small database. The thing is I don't really know if I can just find the database in my computer, copy it in a usb drive and then just plug it in another pc so it can run there.
Can you please tell me if that's the way it works or if I should do something else?
Thanks a lot.
By the way, I use sql server express 2012. If you need to know anything else, just ask. :)
I'm not fan of Attaching and Detaching databases as this leaves no backup on the localdisk but rather just use BackUp and Restore feature.
To Backup:
right click database to which you want to backup
click Task
and select BackUp
fill-in Name and add the Destination
To Restore:
right click Databases
a popup will appear and click Restore Database...
Other Link
Backing Up and Restoring How-to Topics (SQL Server Management Studio)

how to backup SQL database (tables, mappings, indices, etc.)

I am installing a service pack on our shopping cart. They recommend backing up the SQL database before installing. I know we have backups to tape drives done by our hosting company, but I want one I know the exact time stamp for and can access quickly if I need to reload it because of a goof during the upgrade. (I don't want to have the store down for any longer than needed.)
How do you recommend backing up a SQL database for easy reloading for someone who is used to just writing queries and stored procedures? (I'd like to get everything - mappings & indices, etc - because I wouldn't know what all of them are or how to recreate them.)
I access the database via Remote Desktop and can link my hard drive and DVD drives, if that helps. It's MSSQL 2008.
Thank you so much.
Best wishes,
Andrea
BACKUP DATABASE databasename TO DISK='C:\somefile.bak' WITH COPY_ONLY, INIT, FORMAT, CHECKSUM
Obviosly replace databasename and the target C:\somefile.bak as appropriate. Remember, the file and path is on the server; connecting remotely won't change where backup file is stored--in other words it won't be on your local machine.
You can omit the WITH options if you want. Drop INIT if you don't want the target .bak file overwritten. COPY_ONLY isn't a big deal either way in your case. CHECKSUM is just for validating the data before it gets backed up, and may not matter if you don't have CHECKSUMs turned on for the database--though by default starting in MS SQL 2005 new databases were.
The MS documentation for BACKUP and RESTORE isn't too difficult to understand in its basic forms. You can also use the Management Studio Tasks->Back Up or Tasks->Restore GUI if you have access to it.

SQL Server database recovery

I simply copied my .mdf/.ldf files to another file and suddenly my Microsoft SQL 2008 database dies. I can't open these files on another system either. Can anyone explain what's happened? Any way to recover this application's database now?
Did you stop the service or detach the files first?
You are not supposed to copy files when the server is online.
if you want to copy when the server is online, you can right click on management studio , -> detach->
then copy the files to another instance , and choose attach on new server. remember you need to know the location of the files, before you detach, also you should be knowing, also the logins need to transfer.
Have you tried moving the database files back to where they were? (Specifically, stop SQL server, move files, start SQL Server).
Whenever I do this kind of work, I make copies of the files, and rename the original ones (from, say, MyData.mdf to xMyData.mdf). Makes it easier to back out when my fatfingers take over.