-->

Need reference code for SMO in C# SQL Server 2008

2019-06-05 07:33发布

问题:

I googled but cannot find proper simple code for using backup database full and restore the backup, using defaults by using C#.

I am using C# Visual Studio 2008 and SQL Server 2008 R2 evalution but I guess SQL Server 2005 and C# will work too.

The Microsoft site doesn't have code regarding it, it only show description of Microsoft.SqlServer.Management.Smo Namespace......

回答1:

MSDN has a topic Getting Started in SMO that covers a lot of ground - there's also a topic called Programming Specific Tasks which shows how to do certain common tasks in C# with SMO.

And there's a whole series of Getting Started with SMO in SQL Server 2005 which still very much applies to the 2008 and 2008 R2 versions of SQL Server.

Here's another Getting started with SQL Server Management Objects (SMO) article to get you up to speed.



回答2:

Here is an example with VB.NET http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.restore.aspx You can use a converter to get C#: http://www.developerfusion.com/tools/convert/csharp-to-vb/