天道酬勤,学无止境

What to use to open an .mdf (SQL Database) file

Question

I was hoping to be able to open .mdf file. I am using WebMatrix, I can view the queries there. I can read the schema too. But how can I read the file without using WebMatrix. Its SQL Server file not the Comptact edition.

I have searched for web help (Through windows). But all in vain. I will prefer any link or any method to read the basic queries.

Answer1

.sdf is, in fact, a Compact Database file (unless you've changed the extension which would be problematic). SQL Server would be .mdf.

SQL Server (.mdf)

You can attach the database to your local SQLEXPRESS instance and view it. An example of attaching it can be found on msdn: How to: attach a Database File to SQL Server Express. Essentially you're calling:

USE [master]
GO

CREATE DATABASE [database_name] ON 
    ( FILENAME = N'C:\Path\To\<database name>.mdf' ),
    ( FILENAME = N'C:\Path\To\<database name>.ldf' )
    FOR ATTACH ;
GO

SQL Compact Edition (.sdf)

The best tool I've found to open them is CompactView.

screenshot

Answer2

SysTools SQL MDF Viewer can be used to view the table contents. I tried with the free trial version.

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

相关推荐
  • Restoring database from .mdf and .ldf files of SQL Server 2008
    Question For some reason I have to uninstall SQL Server 2008 R2 but before that I copied two files (.mdf and .ldf) of my database from C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.MSSQL2008\MSSQL\DATA Now, the question is, is it possible for me to recover the database from these files in my new installed SQL Server 2008 R2. If yes: then how can I do this? Answer1 Yes, it is possible. The steps are: First Put the .mdf and .ldf file in C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\ folder Then go to sql software , Right-click “Databases” and click the “Attach” option to open
  • SQL Server: Importing database from .mdf?
    Question I have an .mdf file on my local box. I have SQL Server 2008 Express and SQL Management Studio 2008 Express installed on my local box. How in the world do I import this .mdf file as a new database into my SQL Server? This seems like a ridiculously common task that must be performed thousands of times a day across the globe, and I cannot figure out how to do it in Management Studio Express. What am I missing? Answer1 See: How to: Attach a Database File to SQL Server Express Login to the database via sqlcmd: sqlcmd -S Server\Instance And then issue the commands: USE [master] GO CREATE
  • SQL Server 2008 to SQL Server 2005
    Question I have an MDF and LDF file of SQL Server 2005. i attached it with SQL Server 2008 and did some change in data. now when i attached it back to sql server 2005 Express Edition it gives version error. The database 'E:\DB\JOBPERS.MDF' cannot be opened because it is version 655. This server supports version 612 and earlier. A downgrade path is not supported. Could not open new database 'E:\DB\JOBPERS.MDF'. CREATE DATABASE is aborted. An attempt to attach an auto-named database for file E:\DB\Jobpers.mdf failed. A database with the same name exists, or specified file cannot be opened, or it
  • How to attach MDF with no log file? [closed]
    Question Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 years ago. Improve this question I'm trying to attach Yafnet.mdf in SQL Server Management Studio, which does not have a log file. I get the error below. Any ideas how this can be done? An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo) Unable to open the physical file "C:\sql_logs\YAFnet_log.ldf". Operating system error 2: "2(The system cannot find the file
  • Access is denied when attaching a database
    Question I am using SQL Server 2008 developer edition. I was trying to attach the AdventureWorks2008 database. When I tried to attach, I received an "access is denied" error. According to the event log, it came from the O/S: Open failed: Could not open file D:\ProjectData\AdventureWorks\AdventureWorksLT2008_Data.mdf for file number 0. OS error: 5(Access is denied.). I thought "NTFS problem", but System (and I) have modify access to both files. I found that I can successfully attach the database if I log in as sa, but my user account won't work. I am a member of the local administrators group
  • SQL Server Operating system error 5: “5(Access is denied.)”
    Question I am starting to learn SQL and I have a book that provides a database to work on. These files below are in the directory but the problem is that when I run the query, it gives me this error: Msg 5120, Level 16, State 101, Line 1 Unable to open the physical file "C:\Murach\SQL Server 2008\Databases\AP.mdf". Operating system error 5: "5(Access is denied.)". CREATE DATABASE AP ON PRIMARY (FILENAME = 'C:\Murach\SQL Server 2008\Databases\AP.mdf') LOG ON (FILENAME = 'C:\Murach\SQL Server 2008\Databases\AP_log.ldf') FOR ATTACH GO In the book the author says it should work, but it is not
  • Database “cannot be opened because it is version 661” when attaching .mdf file
    Question I am trying to attach MvcMusicStore.mdf to my .\SQLEXPRESS instance (sql server version 10.0.2531) in sql server 2008 R2 management studio. I got the db from this project: http://mvcsitemap.codeplex.com/releases/view/67151 When i am trying to attach i am getting an error?: The database 'C:\PROJECTS\CODEPLEX\TFS10\MVCSITEMAP\BRANCHES\3.1.0\SRC\MVCSITEMAPPROVIDER\MVCMUSICSTORE\APP_DATA\MVCMUSICSTORE.MDF' cannot be opened because it is version 661. This server supports version 655 and earlier. A downgrade path is not supported. Do I need to upgrade my sql server or what else? Answer1
  • recover data from mdf files (ndf being missing)
    Question Our client's server got corrupted and the drives containing NDF and LDF files were gone. The only drive that survived was the one with MDF files. There were no backups of any sort. They recovered the database, which I know just a gist of, by creating new database (from a old database, I guess) and applied bcp utility to copy data over to the new one. But, they would not release the information how they actually recovered. So, I was just curious to find how it is possible to recover data from MDF files only, when the NDF files are lost/missing. Answer1 You will need to restore your
  • Cannot attach the file *.mdf as database
    Question Basically I've followed a tutorial and decided to delete the .mdf file afterwards. Now whenever I try to run the application I get the following error (the title of this thread). The code where I get the error is shown below (ASP.NET MVC 4): OdeToFoodDB db = new OdeToFoodDB(); public ActionResult Index() { var model = db.Restaurants.ToList(); return View(model); } My connection string is the following: <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=OdeToFoodDb;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\OdeToFoodDb.mdf"
  • Sql Server LocalDB Issue In Asp.NET MVC 4 Project
    Question I am getting the following error whenever I am trying to open the db_name.mdf file: The database '{path}\db_name.MDF' cannot be opened because it is version 706. This server supports version 662 and earlier. A downgrade path is not supported. Could not open new database 'db_name.MDF'. CREATE DATABASE is aborted. An attempt to attach an auto-named database for file {$path}\db_name.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. Connection string as follows: <add name="PasswordDBContext" connectionString="Data Source=
  • Windows could not start the SQL Server (MSSQLSERVER) on Local Computer… (error code 3417)
    Question For some reasons I moved this folder : (Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL) to another drive, then returned it to the same location, but sql server has stopped working, showing this error when trying to start it again: Windows could not start the SQL Server (MSSQLSERVER) on Local Computer. For more information, review the System Event Log. If this is a non-Microsoft service, contact the service vendor, and refer to service-specific error code 3417. I tried many solutions discussed in different forums, but none of them work for me. The folder is not compressed
  • Is it possible to access a .mdf database without SQL Server?
    Question I created a .mdf file by SQL Server and put it to a local file. I run my program in a computer which has no SQL Server installed. And also I used classes from the System.Data.SqlClient namespace (i.e. SqlConnection..) I want to make some kind access connection with .mdf file which was created by SQL Server? Is it possible ? Answer1 I don't think it is possible to interact with an MDF file without going through a SQL Server engine. You would most likely install SQL Server Express (which should be an option if you choose to go through add/remove programs for Visual Studio, or you can
  • An attempt to attach an auto-named database for file …database1.mdf failed
    Question I am getting the following error while debugging my visual studio 2010 website: An attempt to attach an auto-named database for file C:\Users...\Desktop\Dpp2012New\App_Data\dppdatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: An attempt to attach an auto-named
  • Connecting to sql server database mdf file without installing sql server on client machine?
    Question I am creating a window application that need to use sql server database. I want to install this application to client machine without installing sql server so that my application can still connect to a database i.e mdf file that i will be providing at client system. How can i connect to a database(mdf) on client machine through my window application without installing sql server. ? I dont know is it possible or not. If possible what will be the connection string in that case. Database need not be used in network. Client mahine dont need any installation. Every thing needs to be run
  • SQL Server: How to attach / repair a detached / damaged database?
    Question A database server crashed. I was able to get the mdf and the log file and I am trying to mount it on another server. I don't have backup as it was a development database. When I try to attach the mdf and ldf files, Sql Server Management Studio give me this error: TITLE: Microsoft SQL Server Management Studio ------------------------------ Attach database failed for Server ------------------------------ Could not redo log record (457:14202:19), for transaction ID (0:478674), on page (1:519205), database 'WSS_Content_5555' (database ID 15). Page: LSN = (370:463:113), type = 1. Log
  • Cannot install adventureworks 2012 database - Operating system error 5: Access is denied
    Question I am trying to install AdventureWorks 2012 database in sql server 2012. I got the mdf file from this link - http://msftdbprodsamples.codeplex.com/releases/view/93587 Here is the name of the file I downloaded - AdventureWorks2012_Database.zip I am doing all this on a windows 7 64 bit. I get the error below: Attach database failed for Server 'SuperPC\SQL2012'. (Microsoft.SqlServer.Smo) For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=11.0.2100.60+((SQL11_RTM).120210-1917+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates
  • How to re-create database for Entity Framework?
    Question I have got into a bad state with my ASP.Net MVC 5 project, using Code-First Entity Framework. I don't care about losing data, I just want to be able to start fresh, recreate the database and start using Code-First migrations. Currently I am in a state where every attempt to Update-Database results in an exception being thrown or getting an error message. Also the website can't access the database correctly. How can I wipe all migrations, re-create the database and start from scratch without having to create a new project? In other words, I want to keep my code but drop the database
  • CREATE FILE encountered operating system error 5(failed to retrieve text for this error. Reason: 15105)
    Question I have a database file .mdf from MS SQL EXPRESS in folder: C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA I would like to attach it to MS 2008 R2 (MSSQL10_50.MSSQLSERVER) but using Server Management Studio I receive the following error: CREATE FILE encountered operating system error 5(failed to retrieve text for this error. Reason: 15105) while attempting to open or create the physical file Do you have any idea how to solve it? Answer1 I was able to solve the problem running MS SQL Management Studio as ADMINISTRATOR. Answer2 It's a Windows permissions issue. If
  • How do I connect to an .mdf (Microsoft SQL Server Database File) in a simple web project?
    Question Specifically, in VS 2008, I want to connect to a data source that you can have by right-clicking on the automatically-generated App_Data folder (an .mdf "database"). Seems easy, and it is once you know how. Answer1 A great resource I always keep around is connectionstrings.com. It's really handy for finding these connection strings when you can't find an example. Particularly this page applied to your problem Attach a database file on connect to a local SQL Server Express instance Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname
  • Delete .mdf file from app_data causes exception cannot attach the file as database
    Question I am building a web application using VS 2012 MVC4 code first. In order to recreate the .mdf file after I changed the model, I manually deleted the file from the app_data directory in VS. I have done this a few times before without any problem. Now I receive an exception: The underlying provider failed on Open. ==> Cannot attach the file MYDB.mdf as database 'MYDB'. I will appreciate your help on how to recreate the .mdf file. Thank you! Answer1 Use SQL Server Object Explorer to delete the database rather than just deleting the .mdf file in Solution Explorer. Otherwise the SQL Server