We upgraded our application to .NET 4.0 a while ago, and now need to add the ability to backup SQL Server 2008 databases from the app. However, it doesn't seem that SMO is available for .NET 4. Is there a workaround or better way to perform a database backup (note that our backups need to be user initiated over a website, so we cannot schedule them).
Asked
Active
Viewed 2,767 times
2 Answers
3
Use BACKUP DATABASE?
-
We'd also need to handle restoring a database as well ... is it easier to just call the SQL commands via a Connection? We were concerned about handling problems/exceptions. – Beep beep Sep 03 '10 at 20:53
-
TRY/CATCH and RESTORE DATABASE? – gbn Sep 03 '10 at 21:12
-
Cool, I had no idea you could do a try/catch within T-SQL – Beep beep Sep 04 '10 at 01:58
2
You can still reference SMO from a .NET 4.0 application, even with it targeting the .NET 2.0 framework.
If you get the Mixed mode assembly is built against version 'v2.0.50727' of the
runtime and cannot be loaded in the 4.0 runtime without additional
configuration information.
exception, installing the latest version of the SQL Server SDK (SQL Server 2008 R2) should fix it, even if the machine is running an older version of SQL Server e.g. 2005.

John Mills
- 10,020
- 12
- 74
- 121
-
2You can vote for 4.0 support for SMO here: https://connect.microsoft.com/SQLServer/feedback/details/643811/net-4-0-compatible-smo – RobSiklos Mar 10 '11 at 15:24