Importing a MDF file into SQL Server 2008? - sql-server

I have inherited a VB.net web app that I'm making some changes on. I'm perfectly capable with the programming side (VB and MSSQL) but I'm getting lost with the tools. I was given a zip file of the code and everything. I opened the sln file in Visual Studio 2005 and it worked fairly easily with little modification.
Running the app works perfectly. Problem is, I need to write some new SPs so need the database admin. SQL Server 2008 Express is installed but it doesn't see any database and I have no idea how to import it.
I have a folder App_Data in the project with the file ASPNETDB.MDF. Opening this in VS gived the error:
This server version is not supported. You must have Microsoft SQL Server 2005 Beta 2 or later.
Any ideas where to go from here?

You need to get Sql Server Management Studio. From there you should be able to connect to the instance of Sql Server Express running on your system and tell it to attach to the .mdf file. This will allow you to use that database from withing sql server and management studio, and you will be able to add your stored procedure. Just remember to detach again when you're done, or you won't be able to use the mdf file as you expect from your app.

Visual Studio uses SMO 2005 to connec to to SQL. The SMO 2005 will not connect to SQL 2008 by design. You need to either upgrade VS to VS 2008, or downgrade Express to Express 2005.

You can't attach mdf file made in SQL Server 2005 to a SQL Server 2008 instance. What you need is to install SQL Server 2005 Express, attach this file, backup database, then restore it on 2008 Server instance and detach the database. You will get properly created for 2008 Server mdf.

Related

SQL Server - Copy database from Server 2008 to Server 2012

I have two servers one in Denmark the other here in the UK. I need to make a copy of a database out of SQL Server Management 2008 (1st server) and place it in SQL Server Management 2012(2nd server). I have tried connecting to the remote server but have been getting difficulties so instead of connecting both up and doing it that way I was hoping there is a function like copy database which could do this for me. I have gone into tasks and copy database in SQL Server 2008 but in the Copy Database Wizard that appears it says "You can use this wizard to move or copy databases from an instance of SQL Server 2000 or later to an instance of SQL Server 2008". I'm looking for something like this that will work for Server 2012.
Copy your database file .mdf and log file .ldf and paste in your SQL Server
Install file in Programs Files->Microsoft SQL Server->MSSQL10.SQLEXPRESS->MSSQL->DATA.
Open SQL Server. Right-click on Databases then Select Attach... option.
You can create a backup with the Management Studio on the source and restore it on the target.
You need Management Studio 2012 to make this step. You can then create empty database on 2012 server. Right click on this empty DB->Tasks->Copy database..
Wizard will guide you. You should to this under 2012 Management Studio because it is compatible with 2008 Server - vice versa it will not work.
Of course, cleanest way is to do this via backup (.bak file - Tasks->Backup.. then on 2012 server Tasks->Restore->Files or FileGroups) but you need remote access (RDP) to the server.

How to view an mdf file Visual Studio 2012 creates to store ASP.Net MVC 4 project data?

I've created a new ASP.Net MVC 4 project in Visual Studio 2012 and figured out that it creates a file with a .mdf extension to store the data.
I would like to view the database schema and be able to query it manually the way I can query a SQL Server database with SQL Server Management Studio.
How to do that?
.mdf IS SQL Server ... just attach the .mdf to your SQL Server instance, and you can have a look at it using SQL Server Mgmt Studio.
This whole AttachDbFileName= features is crap - sorry. I would never use such an approach to fiddle around with .mdf files. Just attach the .mdf file to your SQL Server instance, and then the database will be on the server (where it belongs) and you can see it there (and use it from there - update your connection string to connect to the server and the database on the server).

SQL Server version 612 , 655?

I have SQL Server 2008 and VS2008 installed on my computer and I am trying to run a web application I've created on a computer which has SQL Server 2008 and VS2008 and VS2010 beta 2 with its SQL Server Express.
I am getting an error with the database version that is
"...aspnetdb.mdf" cannot be opened because it is version 655. This server supports version 612 and earlier...."
Configuring the database in Visual Studio ->Tools -> Options -> Design-Time Validation Database is not working since I don't have the SQL Server version comes with VS 2010.
EDITED : I also edited aspnetdb and inserted a few more tables so I need the same aspnetdb
Is there any solution to convert this db ?
Also, after fixing this, I am looking forward to upload it on my hosting which has SQL Server 2005 DB and configure it in PLESK.
The SQL Server databases have a version specific format. Each SQL Server runtime version (SQL 2008 SP1, SQL 2008 RTM, SQL 2005 SP2, SQL 2005 SP1, SQL 2005 RTM etc) knows how to upgrade to its own verison. Unfortunately, once upgraded the database cannot be downgraded. So if your MDF was upgraded to version 655, it cannot be downgraded to any prior version. If you know you're going to deploy on SQL Server 2005, you must develop on SQL Server 2005 too. Not only that, but the actual build number of your development has to match the build number of the deployment (or at least be lower than that): the SP level and CU level must match.
You can a attach the 2008 version MDF you created to a SQL Server 2008, script out the database content, then import the script into a SQL Server 2005 database of the proper version.
I had this problem and when I changed my_computer_name\SQLEXPRESS with . to connect to server and it works and I could attach MDF file
may be you have both services run. (Mssql2008 and mssqlexpress) Maybe you have runing the mssqlespress running, that's the error that you have. Try to stop the mssqlserver express service and run mssql2008 services, and attach again your databases. I try this and works for me

Configure VS2008 to create SQL Server databases instead of SQL Server Express?

Probably asked and answered before, but difficult to search for.
In VS2008 when you right-click App_Data folder and create new database, it attempts to create a SQL Server Express database. Well I have SQL Server 2005 Standard installed and have thus uninstalled Express. How do I get VS2008 configured to know I want SQL Server databases (NOT Express) created?
SQL Server Express databases are SQL Server databases and vice-versa. While is true that the SQL Server 2008 database files format is different from SQL Server 2005 one, whthin the same version (2005, 2005 SP1, 2005 SP2, 2008 , 2008 SP1 etc etc) all SKUs (Express, Standard, Exnterprise etc) have all the same datbase format.
Yout Visual Studio tools are guiding you down the wrong path. You should not use the Solution Explorer to add a database to the App_Data folder. Instead you should use the Server Explorer tool (menu View/Server xplorer or press Ctrl+W,L) and connect to your SQL Server 2005 instance. Then use the Server Explorer tool to explore the database. To connect to the database from your solution, add a connection string to the web.config file.
While you can manage the database objects from the Server Explorer, thar is a horrible way to do it and will cause only pain on the long run. You should instead create deployment scripts with DDL statements and run those scripts when the solution is deployed. This way your database metadata is part of your source control and you can keep track of application database versions, see Version Control and your Database.

How do I open a local SQL server database file outside of Visual Studio?

Is it possible to open a .mdf database file created in Visual Studio with some external SQL server IDE like Quest Toad for SQL server? Databases created in Visual Studio are rather similar to simple Access databases in that they're a single file.
It appears external IDE's like Toad can't see the .mdf being served by my localhost's SQL server instance under MYMACHINE\SQLEXPRESS - I assume because these files are only served within Visual Studio with the .Net framework provider for SQL server, so my local sql server instance doesn't serve these files. Is that the case? Is there some way to access these databases locally outside of Visual Studio?
Thanks in advance!
What you are seeing are user instances. Sql Express only loads those upon request with a special connection string. It is possible to use Sql Management Studio Express in combination with the SSETool to load an instance so you can management more details
Download TOAD for SQL Server.
You don't point TOAD to an MDF file. You point it to the SQL Server application that is serving the MDF file. If you are using SQL Server Express (2005), the server would default to ./SQLEXPRESS and you would use Windows authentication.
a problem you may be having with sql express is it might not be on the standard port, look at my answer here to see if it helps: https://stackoverflow.com/questions/449607#449656

Resources