How to attach database in SQL Server 2008 which was created in SQL Server 2012 - sql-server-2008

I have two database files named as .mdf and .ldf which are created in SQL Server 2012 and now on my pc I installed Visual Studio 2010 and SQL Server 2008 Express.
When I try to attach these database files to SQL Server 2008 it gives me error.
The database 'C:\PROGRAM FILES\MICROSOFT SQL
SERVER\MSSQL10.SQLEXPRESS\MSSQL\DATA\CMS_DB.MDF' cannot
be opened because it is version 706. This server supports version 655
and earlier. A downgrade path is not supported.
Could not open new database 'C:\PROGRAM FILES\MICROSOFT SQL
SERVER\MSSQL10.SQLEXPRESS\MSSQL\DATA\CMS_DB.MDF'. CREATE
DATABASE is aborted.
An attempt to attach an auto-named database for file C:\Program
Files\Microsoft SQL
Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\CMD_DB.mdf failed. A
database with the same name exists, or specified file cannot be opened,
or it is located on UNC share.
When open database in ssms 2008 then error :
Attach database failed for Server 'MATRIX-PC\SQLEXPRESS'. (Microsoft.SqlServer.Smo)
Additional information:
An exception occured while executing a Transact-SQL statement or batch.
(Microsoft.SqlServer.ConnectionInfo)
The database 'C:\USERS\RAJ\DESKTOP\COLLEGE MANAGEMENT SYSTEM(.NET 4.5)\ COLLEGE MANAGEMENT SYSTEM\BIN\DEBUG\CMD_DB.MDF' cannot be opened because it is version 706.
This server supports version 655 and earlier. A downgrade path is not supported.
Could not open new database 'C:\USERS\RAJ\DESKTOP\COLLEGE MANAGEMENT SYSTEM(.NET 4.5)\COLLEGE MANAGEMENT SYSTEM\BIN\DEBUG\CMD_DB.MDF'. CREATE DATABASE is aborted.
(Microsoft SQL Server, Error: 948)

No, you can only move forward.
This means, you can restore the database from 2005 or 2008 to 2012 version but can not do it in reverse order. The next most popular question I receive is if we can’t restore a SQL Server 2012 database to earlier version what is the next best option?
I have personally faced this issue once before and I had manually created T-SQL script using Script and Data Generator Wizard in SQL Server 2012 and rebuild my database in
SQL Server 2008R2. If you have many different databases which you want to address, you can use SSIS to
automate the script generation.

As noted if you want to access a 2012 db from 2008 you will have to migrate the database back to 2008. This will only be possible if you have not used 2012-specific features in the db. If you have and still want to perform the migration you should first try and identify these where they occur and fix those first.
As noted above one option is to generate T-SQL scripts and use these to regenerate the db in 2008. However for a large db this could be time consuming and hard work to get to actually work.
A better option than using the SSMS scripting wizard is to use a similar tool available on Codeplex called SQL Database Migration Wizard - http://sqlazuremw.codeplex.com/releases/view/32334. You want the latest version v4.x to work with SQL Server 2012.
The tool is originally intended to be used for migrating databases between SQL Server and Azure. However the tool works just as well between SQL Server 2012 and SQL Server 2008. The trick is to set SQL Server rather than Azure as the target in the advanced options.
The reason this is a better option than the SSMS scripting wizard is that it uses BCP for the data transfer rather than TSQL and so is much more efficient. I migrated a 7GB database in about 2 hours with this with most of the time spent drinking tea while the machine worked away. Importantly, it all just worked with no requirement for me to start editing files to fix problems like too many commands, timeouts etc.

Related

Is it possible to use a SQL Server backup and link it to Visual Studio 2012 or you need the .mdf file?

I have a SQL Server backup from my server and I have a comfortable way to access the daily SQL Server backups.
I want to do some asp.net coding using Visual Studio 2012, and I do not want to install SQL Server on my machine since it is too heavy and slowing down the system.
I see that you can add .mdf file to a project and use it as a standard database:
is it possible to do the same with SQL Server backup?
is it possible to extract .mdf file from SQL Server backup without SQL Server?
Thank you in advance,
M.
SQL Server is one programs runs only in service mode, so you need to have it's server running to gain it's services. The answer is NO, but you can use SQL Server Express or other stuff.
After you had a server running, you can use SQL Assembly to access .mdf file directly, not bu addressing server. You will need to create a connection string like :
Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;
And put mydbfile.mdf into the Data directory.

Error when restoring database to a new server

I receive the following error when I try to restore a database to SQL Server 2008 from SQL Server 2008 Express R2:
The database was backed up on a server running version 10.50.2500.
That version is incompatible with this server, which is running 10.00.4064.
Either restore the database on a server that supports the backup, or use a backup
that is compatible with this server.
Is there anything that I can do to fix this or am I stuck using SQL Server Express?
You cannot go "back" in SQL Server versions - if your database is on 2008 R2 (v10.50) - you cannot back it up and restore it onto a 2008 (v10.00) version.
There's no trick, no workaround, no hack - it just cannot be done - period.
So you either need to upgrade your target system to 2008 R2 as well (Express will do, as long as the size is below 10 GB), or you need to script out structure and data to .sql files to run those on your "old" 2008 system (possibly using third-party tools like Red-Gate SQL Compare / SQL Data Compare to create those scripts and possibly run them against the target server directly).

Is it possible to export a database from SQL Server 2008 and import it into SQL Server 2005?

I need to move a database from SQL Server 2008 to 2005, did the backup format changed or can I import the exported DB in the SQL Server 2005?
The database has tables, views and stored procedures, and it is not using any 2008 specific features.
If it's not possible, would setting the compatibility mode to SQL-Server 2005 (90) help in this case?
Thank you.
Select your database in SSMS, right-click, select Tasks, select Generate Scripts. In the dialog box that pops-up, enable all options, including script data and make sure you select "Script for SQL Server 2005". Execute the generated scripts on your SQL Server 2005 machine. This is workable only for a relatively small database, of course. Else, you'll have to export/import data via bcp.
You won't be able to do this - the backup file contains a version number, and SQL 2005 will refuse to restore the backup. Similarly, you won't be able to detach and reattach the raw data files.
The only option you have, short of upgrading SQL 2005 to 2008, is to export the SQL schema and sprocs using SSMS's ability to generate scripts, and then migrate the data using (for example) BCP or an SSIS package.
There will be third party tools that might be able to help with some of this (for example, a combination of Redgate's SQL Compare and SQL Data Compare). However this is something you will have to research.

SQL Server 2008 to SQL Server 2005

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
is located on UNC share.
I know what the problem is, it is quit descriptive error. but was asking the solution of that problem. anyway thanks to everyone for there reply.
anyone facing same problem, see the tread below and read LEKSS reply
http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/46ce6099-61c6-4526-9dda-10a3359386cb
hope this will help
Update: Quoted external link for safe keeping
The database 'ASPNETDB.MDF' cannot be opened because it is version 655. This server
supports version 612 and earlier.
You cannot backup/restore or
detach/attach from a higher version to
a lower version.
Use database publishing wizard to get out the script for all objects in
2008 db
http://www.microsoft.com/downloads/details.aspx?FamilyId=56E5B1C5-BF17-42E0-A410-371A838E570A&displaylang=en
http://blogs.msdn.com/webdevtools/archive/2007/10/15/sql-database-publishing-wizard-is-now-in-visual-studio-orcas.aspx
http://msdn.microsoft.com/en-us/library/bb895179.aspx
Create a new empty database in your 2005 instance .
Execute the above generated script in your new 2005 database.
Move your SQL server logins/users from 2008 database to 2005 database
using sp_help_revlogin stored
procedure.
Thanks, Leks
Proposed As Answer byyup. _ Sunday, May 09, 2010 10:14 AM
Marked As Answer byTom Li - MSFTMicrosoft,
ModeratorThursday, May 20, 2010 4:58
AM
Your MDF and LDF are now version 655 (the SQL 2008 version). As the error message clearly states, there is no downgrade possibility. From now on, you can only attach these files to SQL Server 2008 or to SQL Server 2008 R2 (which will upgrade them to 661 btw). You can never attach these files back to a SQL 2005 instance.
I know this was answered but this one solved the problem for me:
database-cannot-be-opened-because-it-is-version-655
basically remove "\SQLEXPRESS" from connection string value.
instead of:
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\OTJDB.mdf;Integrated Security=True;User Instance=True
use:
Data Source=.;AttachDbFilename=|DataDirectory|\OTJDB.mdf;Integrated Security=True;User Instance=True
It's because the file formats are fundamentally different. If you attach the file to SQL server 2008, you MUST upgrade your express edition to at leas. The version you last attached the file to.
So you only have 2 choices: upgrade or ditch your file and redo your updates on a 2005 install.
It is a one way street, you can always go up aversion but never down a version, this is because of meta data changes
Man I ran into this problem too. But here is an even easier way to over come this:
What I did is copy my original .MDF DB file from my source files on my development machine where I keep backups of all my .MDF files using Visual Studio earlier versions and then copied the file directly to the server since I have direct access to my server.
I just pasted the file in to the server Inetpub location where the App_Data folder for my website files and voila! No more compatibility issues.
Then using SQL Server Management Studio reattach the DB file that you just pasted into the Inetpub and it worked!

Using Visual Studio 2008 DBPro to convert database from Sql 2005 to Sql Server 2008

I have a DBPro database project that was created for Sql 2005. I am trying to build this on a different environment, with Sql 2008, and I am getting the following error:
MSBUILD : Build error TSD158: An unsupported target database version was encountered.
I couldn't find much on this error, and I am unclear what is the conflict. I have tried to change the buildversion element in the database project from 9.0.21022.8 to 10.0.0.0 but that didn't make any difference. I am out of ideas. Any thoughts?
To target SQL Server 2008, don't you need some GDR update? See http://blogs.msdn.com/gertd/archive/2008/11/25/visual-studio-team-system-2008-database-edition-gdr-rtm.aspx
Also, it might be easier to take your database, restore it on SQL Server 2008 (and let the database upgrade the database itself). Then just start a new project where you suck down the schema. But I still think you'll need the GDR in order to do that.