How can I attach a database? - sql

When I want to attach database, an error occurs:
The database 'Almizan' cannot be opened because it is version 661.
This server supports version 655 and earlier. A downgrade path is not supported.
Could not open new database 'Almizan'. CREATE DATABASE is aborted.
(.Net SqlClient Data Provider)
Help me to attach this database.

Install SQL Server 2008 EXPRESS R2. There is a bug in the Web Platform Installer and it still thinks EXPRESS R1 is the latest version.
SQL Server 2008 databases are version 655. SQL Server 2008 R2 databases are 661. You are trying to attach an 2008 R2 database (v. 661) to an 2008 instance and this is not supported. Once the database has been upgraded to an 2008 R2 version, it cannot be downgraded. You'll have to either upgrade your 2008 SP2 instance to R2, or you have to copy out the data in that database into an 2008 database (eg using the data migration wizard, or something equivalent).
The message is misleading, to say the least, it says 662 because SQL Server 2008 SP2 does support 662 as a database version, this is when 15000 partitions are enabled in the database, see Support for 15000 Partitions.docx. Enabling the support bumps the DB version to 662, disabling it moves it back to 655. But SQL Server 2008 SP2 does not support 661 (the R2 version).

Think you need to upgrade the SQL Server 2008 instance (655) your trying to attach the database in, to SQL Server 2008 R2 (661), the version the database was actually created in.
See SQL Server: Attach incorrect version 661

The this answer on the MSDN seems to tell us the obvious
http://social.msdn.microsoft.com/Forums/en-US/sqlexpress/thread/01ed3b1c-6f29-4518-a3a4-e4e35decc05f/
When you attached the database to SQL Server 2008 to compress it the
database has automatically been upgraded from SQL 2005 to to SQL
Server 2008 from the disk structucture point of view. An internal
upgrade script has been run and has modified the on-disk structure of
the database to that new version. This can be seen at the version 655.
Once this has been done you can no longer attach the upgraded database
to a lower version of SQL Server, it will fail with the error you've
seen.
This has nothing to do with the compatiblity level of the database.
The compatabilty level only prevents the engine from using some of the
new features.
In order to get the database on SQL Server 2005 again you will need to
create the database freshly and export/import the data, for example by
using the Export/Import Wizard.
Ulrike - MSFT

Related

Can't Attach Northwind database as it's version 661. Server supports 612 and earlier [duplicate]

When trying to attach a database file to:
Microsoft SQL Server 2008 (SP2) - 10.0.4000.0 (X64) Sep 16 2010 19:43:16 <X64> (Build 7600: )
I get this error message:
The database cannot be opened because
it is version 661. This server
supports version 662 and earlier. A
downgrade path is not supported.
Any idea why? and how to solve it?
SQL Server 2008 databases are version 655. SQL Server 2008 R2 databases are 661. You are trying to attach an 2008 R2 database (v. 661) to an 2008 instance and this is not supported. Once the database has been upgraded to an 2008 R2 version, it cannot be downgraded. You'll have to either upgrade your 2008 SP2 instance to R2, or you have to copy out the data in that database into an 2008 database (eg using the data migration wizard, or something equivalent).
The message is misleading, to say the least, it says 662 because SQL Server 2008 SP2 does support 662 as a database version, this is when 15000 partitions are enabled in the database, see Support for 15000 Partitions.docx. Enabling the support bumps the DB version to 662, disabling it moves it back to 655. But SQL Server 2008 SP2 does not support 661 (the R2 version).
To clarify, a database created under SQL Server 2008 R2 was being opened in an instance of SQL Server 2008 (the version prior to R2). The solution for me was to simply perform an upgrade installation of SQL Server 2008 R2. I can only speak for the Express edition, but it worked.
Oddly, though, the Web Platform Installer indicated that I had Express R2 installed. The better way to tell is to ask the database server itself:
SELECT ##VERSION

how to attach .mdf file to sql server 2008 EXPRESS

I have .mdf files created using SQL SERVER management studio in another computer and wish to attach the same to SQL SERVER 2008 EXPRESS in another computer. How should I do so?
I tried this method :How to: Attach a Database File to SQL Server Express
but then it shows an error that the database cannot be created due to compatibility issues.
Msg 948: The database xyz cannot be opened because it is version 706.
This server supports version 655 and earlier. A downward path is not
supported..
....
This basically means your SQL versions don't match. For example, if you backup a database on SQL 2012, you can't restore it to 2008. In your case Version 706 is a database file from Sql Server 2012 and Version 663 is a database file from Sql Server 2008R2 (with some SP).
You can either install SQL Express 2012 to attach the MDF, or if you can't do that, you would have to script out your schema and data and create the DB from scratch.. Unfortunately there's no way to 'downgrade' and MDF back to an older version of SQL.
The message is very clear:
The database MDF file is version 706. Your server understands version 655 . Which means, despite to your claim to the contrary, that you are connected to a SQL Server 2008.
Install a SQL Server 2012, connect to it, and attach your database.
Please pay attention during the installation process to the instance name you choose and make sure you connect to that instance.
You can also check now what instances you have installed, look at what services you have on your system.
SELECT ##VERSION AS 'SQL Server Version'

SQL server version 655

what update i need to install for version 655 in vs studio 2010 for the sql server.
Can anyone tell me what i need on my computer when creating a database using sql on vs studio 2010? I need to use version 655 cos thats the version being used on Uni Computers
SQL Server 2008 (655) and SQL Server 2008 R2 (661) are not the same thing (though it is a common misconception - a lot of people think they're the same because Microsoft made a terrible, terrible, terrible naming decision, making 2008 R2 sound like a service pack).
You can't attach/restore a 2008 R2 database to a 2008 instance, period. Though there are several workarounds (that also apply for attaching 2012 -> 2008, 2008 -> 2005, 2008 R2 -> 2005, etc). You can either upgrade the engine you're trying to connect to up to 2008 R2, or you can extract the schema / data from the database using generate scripts wizard, import/export data wizard, SSIS, or 3rd party tools like Red Gate SQL Compare (for a full list of alternatives see this blog post).
This comes up extremely often, did you search for "sql server version 661 655"? I came up with a whole bunch of hits using this search term and some slight variations, all on this site and dba.SE:
Failure attaching SQL Server 2008 database to SQL Server 2005
Cannot attach 2008 R2 database to 2008 instance
Database restore error
Create Database in SQL Server 2012, Script and Use in 2008?
Cannot restore backup on SQL Server Express
How to automatically restore a SQL Server 2008 R2 backup file
Database "cannot be opened because it is version 661" when attaching .mdf file
Use database 661 version with SQL Server 2008
SQL Server: Attach incorrect version 661
https://dba.stackexchange.com/questions/21525/restoring-an-sql-server-2012-mdf-to-sql-server-2008
https://dba.stackexchange.com/questions/20588/restore-sql-server-2012-backup-to-a-sql-server-2008-database
If you are developing .NET based apps in visual studio 2010, then they will typically support all versions of Microsoft SQL Server. That does not mean you install SQL server INSIDE of visual studio, just that you can connect to a SQL Server instance running somewhere.
If you are asking "Where can I get a copy of SQL Server that my university is using?", that depends. For development, you can use a SQL Express installation on your local machine that matches the major release of SQL (2005, 2008, 2008R2, 2012), or you can request the university (or someone else) grant you access to an existing SQL instance.

How to automatically restore a SQL Server 2008 R2 backup file

My team needs to update an automated content process running over SQL Server 2008 servers to include the content of a SQL Server 2008 R2 database delivered by a third-party vendor.
The request to third-party to deliver us on SQL Server 2008 is NOT an option.
My common sense indicates there is no way to downgrade from 2k8 R2 to 2k8 as in most of the software products I know. However, I'm wondering if I would be able to do something like this in a script:
Restore SQL Server 2008 R2 .bak file onto our SQL Server 2008 R2 instance
Update compatiblity level to SQL Server 2008 (100). Here is the bug in my plan: I've not found any compatiblity level distinctions between 2008 versions in internet. Any clue on this?
Backup the database.
Restore the database in SQL Server 2008
There may be some other ideas you may want to share with me.
Just recall there should not be manual intervention on this database conversion since this operation needs to be incorporated to an automated process.
Any help/suggestions/comments will be welcome!
No, you cannot restore a database backwards, regardless of compatibility level. Compatibility level affects certain database engine behaviors, but does not downgrade the database version. You will never be able to restore onto 2008 a database that ever existed in a 2008 R2 instance.
For workarounds, you can:
restore the database on R2, then use the import/export data wizard (or a third party tool) to transfer schema / data to the 2008 instance (and you should be able to automate this to some extent, e.g. Red-Gate's tools have command-line interfaces)
upgrade your 2008 servers to 2008 R2 or 2012
push back on the vendor
By design, you can only restore a DB backup to the same or newer version of SQL Server. A backup created with SQL Server 2008 R2 can only be restored with SQL Server 2008 R2 or SQL Server 2012. This is regardless of the compatibility level of the database. It's a limitation of the backup and restore procedures. This has been a limitation since prior to SQL Server 2000 (i.e., every version I've ever used).
Maybe you can script out the creation of new database, instead of backing up and restoring you basically just do a data dump with script.
Try looking at this How can I get a SQL dump of a SQL Server 2008 database?

Error: Can't attach DB to SQL Server 2012

I have SQL Server 2012 and I'm trying to attach a db which was previously used with SQL Server 2012, surprisingly I'm getting the following error:
The database 'DatabaseName' cannot be opened because it is version
706. This server supports version 622 and earlier. A downgrade path is not supported.
I don't really understand how this could happen since like I said it was used with same 2012 version. What am I doing wrong? How can I make it work? Please explain in detail how this can be resolved.
Thank you!!
The error sounds like the server you are trying to attach the database to is not SQL Server 2012. This may be the version of Management Studio / Management Studio Express you're using, but I suspect SELECT ##VERSION; will tell you something different. It may just be a connection string mixup if you have multiple instances of SQL Server installed, otherwise you should download and install SQL Server 2012 Express from here.
#source
It sounds like you had the following configuration and source databases:
SQL Server 2008 SP3 (ver 10.0...) - database engine
SQL Server Management Studio 2012 (ver 11.0...) - management tools
a database that was created with SQL Server 2012 (version 706)
As mentioned you could install SSMS for SQL Server 2008 (after you uninstall SSMS for SQL Server 2012). Then you would have to script your database for that version and re-run the script via 'Tasks>Script...', remembering to set the target server version as shown below.
After scripting you can then use the import/export wizard to export and then inport the data into the new (downgraded database), assuming the database had no 2012-only datatypes (such as sequences).
Another consideration is database compatibility level as shown below. You can have a SQL Server 2012 instance which hosts databases with various compatibility levels.
Using SELECT ##VERSION works very well for me. Your Database Engine is connected to a 2008 DB which certainly doesn't allow you to attach. Once I change my Database Engine to connect to 2012 DB, it works for me.
Check your Database Engine connection. You can be working on 2012 Management Studio yet connecting to 2008 DB. This is what happened to me and I have solved it use SELECT ##VERSION.