Conversion from LocalDB (.mdf) file to SQL Server Express .mdf file and reverse process - sql-server-express

Since we need to move around our database a lot (like update it with new Rows which are generated by code and then update it prod db and reverse process). SQL Server CE, being a file based system was very helpful.
We would like to upgrade to use SQL Server Local Db but at the same time, it has limitations of use with IIS (though possible with AttacheDbFile). In this regard, since LocalDb is more or less a version of SQL Server Express, would it be possible to use our SQL Server LocalDB .mdf in our development environment and then copy them in prod but use by attaching to a SQL Server Express instance?
If yes, what additional thing, we need to do make it possible?
Also, we would like the reverse process to be worked out as well, mean detach the .mdf file and use it as LocalDb in development environment. I have read the great blog articles of
Krzysztof Kozielczyk also but not have experimented much with LocalDb.

LocalDB IS SQL Server Express (introduced with SQL Server 2012 Express), and the .mdf file is identical between LocalDB and SQL Server Express (and even a "full" SQL Server edition like Web, Standard or Enterprise Edition).
The only caveat is: you need to be using the same versions of those databases, since the file format is only identical amongst same versions, and can only be used amongst the same versions (e.g. 2012) - or it can be "upgraded" to the next newer version (e.g. you could move a database from LocalDB 2012 to a SQL Server 2014 Express once it's released) - but you can never go back down to an earlier version (you cannot take a LocalDB 2012 .mdf database file and attach it to a SQL Server 2008 version).

Related

SQL Server 2005 mdf file on 2012

I have a SQL Server 2005 .mdf file I need to install on a server. Can I simply install SQL Server 2012 Express and attach the .mdf file without any issues, or should I stick to 2005 Express to eliminate any issues that may arise?
I should also add it needs to support a ASP.NET 3.5 website.
Cheers
If you have all files (mdf, ldf and potentially multiple ndf) and the database was cleanly shut down, you won't have an issue attaching to 2012.
If you have only the mdf it might work but it could also fail.
Either way, first take a backup of the files you have.
That being said, make sure you don't use any features that changed between 2005 and 2012 (see http://technet.microsoft.com/en-us/library/ms143532.aspx for details)

Transfer a database to SQL Server 2008 from SQL Server 2008 Express

Anyone know the generic practices transfer the database to SQL Server 2008 from SQL Server 2008 Express (I'm not sure it is r2), when I try to attach the .mdf file from Express, there is an error message.
the database cannot be opened because it is version 661. This server supports version 655 and earlier. A downgrade path is not
supported.
Well, the message is clear: the file you're trying to attach from Express is from a newer version of SQL Server
So it appears that you indeed have SQL Server 2008 R2 Express, and you cannot attach this to a SQL Server 2008 instance. There's no way, no hack, no workaround, no trick, or no third-party tool to achieve this - it just cannot be done - period.
So you either need to upgrade your main instance to SQL Server 2008 R2, too - or you need to find another way (like scripting out the structure and/or data into .SQL files) to move your changes from one instance to the other - or use a third-party tool like Red-Gate SQL Compare to synchronize the changes between the two instances.

Will SQL Server Express work with a database made in regular SQL Server?

I was wondering if we could backup the database that we currently host on regular SQL Server, and put it onto our clients computer when we setup SQL Server Express for them.
Is this possible?
Thanks,
Matt
Yes, it's possible to restore a database backup from the Standard edition to the Express edition. It's not possible to restore a SQL Server 2008 to a SQL Server 2005 version, though.
However, there a some minor differences between versions. I've noticed an issue in SQL Server Express 2005 when calling .NET SQL CLR functions across databases, so your mileage may vary. I haven't been able to find a good overview of the exact differences between the various SQL Server editions.
It's always best to keep the development platform as close as possible to the release platform. I can only recommend that you use the Express edition of SQL Server for development as well; and re-test your application.

Do I have both SQL Server 2005 and SQL Server 2008 installed?

When in 'SQL Server Configuration Manager' I see, under 'SQL Server Services', 2 items that look like SQL Server's:
SQL Server (sqlexpress)
SQL Server (mssqlserver)
Does that mean I have 2 versions installed at the same time? The 'SQL Server (mssqlserver) is currently stopped).
You have two instances. They might or might not be the same version (meaning 2005/2008).
Express is just an SKU / edition from the myriad of different editions.
You can have the same version or multiple versions/SKUs installed as different instances on the same machine.
So unless someone wittingly set up a new instance with the name "sqlexpress", you probably have two kinds of products installed (both can be 2008 or both can be 2005 or they can be different - it is just that one of them is presumably the Express SKU while the other is say Standard.)
You can get more information on the instances by using ##VERSION.
It looks like you got SQL Server Express installed with Visual Studio and then later installed SQL Server 2008. I've done this before and the best solution I found was to completely uninstall SQL Server Express and SQL Server 2008. Remove all the files in the Microsoft SQL Server directory in Program Files, then reinstall SQL Server 2008. If you still have problems getting the 2008 instance to be the default, you may also need to uninstall Visual Studio.
In the future, if you're going to install the development (or other) version of SQL Server locally, I suggest making sure you install it before Visual Studio. The VS install won't install SQL Server Express if it detects an existing SQL Server instance on the system.
BTW, you can verify if this is true by using the Add/Remove Programs Control Panel item.
SQLExpress is the light/free edition, usually used for developers or very lightweight applications.
MSSQLServer is the full blown SQL install.
So yes you have 2 "SQL Server" installs, but they are different products, I can't say which versions based on your provided data.
You have two SqlServer instances installed on your system. One is SqlServer Express Edition and the other one a Sql Server. I can't say which version or edition.
Maybe you can find some more information in the registry (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft).
I'd vote against removing either one--SQL server does fine with multiple instances and they are good for different things. For example, lots of open source projects presume a local copy of sql express at .\SQLEXPRESS for development use. Whereas you can't write analysis service stuff with SQL Express.
Or, its not a problem. Those aren't the droids your looking for. Move along.

Importing Sql Server 2005 database into Sql Server express 2008

Is there any way to import a database backup from 2005 into 2008 express edition. What I've had to resort to is doing a script the database, then import all the data through DTS. Whenever I tried to import straight from a backup file it says something about not being to import into a new version of sql server or I'll get the below error.
title: Microsoft SQL Server Management Studio
Specified cast is not valid. (SqlManagerUI)
SQL 2005 backups should be restored on 2008 without problem (have done that myself many times). What exact error message did you got about versions?
The other error (Specified cast is not valid) seems to be Management Studio error, not server error. Have you full rights on 2008 server?
Look at this question - any-reason-to-have-sql-server-2005-and-2008-installed-on-same-machine - there are talked both about restoring SQL2005 backups and about attaching SQL2005 data files.
(Of course you cannot attach production databases. To attach non-production databases just detach them, make file level copy of these and attach copies to new server. Orginal files need to attach to original server too :))
I imagine that you are in a development process where your data will have to be regularly copied to you SQL 2008 server.
You can then think of configuring a replication between the SQL 2005 server (publisher) and SQL Server Express 2008 (suscriber). Depending on your requirements, you have the choice between snapshot or merge replication. If no update is done on the suscriber side, go for snapshot.
Once you want to have your 2008 server running independantely from the publisher, just delete the replication.
A valid SQL Server 2005 Express backup file should be able to be restored to SQL Server 2008 Express. If the SQL Server 2005 backup is from the Standard or Enterprise versions, you might hit problems restoring it to Express. The user context that the backup was created from should not affect the ability to restore that backup.
One thing you can do is to try running the restore operation as a verification, without actually trying to run the restore. That will tell you if the backup file is valid or not. You can use this syntax:
RESTORE VERIFYONLY
FROM yourbackupfile.bak
If possible, I would also suggest trying to simply detach the original database from 2005 and then attaching the file at the 2008 edition.
While I have only tried this with the standard edition myself, it has worked perfectly with the compatibility mode keeping the database set to 2005.
Have you tried running the Upgrade Advisor http://www.microsoft.com/download/en/details.aspx?id=11455 - it might be able to highlight problems for upgrading the original database.