I want to write c# code to make a snapshot-backup if available. This is supported since SQL Server version 2005 but only in Enterprise edition but not in Express or Standard edition.
如果有的话,我想编写c#代码来进行快照备份。这是自SQL Server版本2005以来所支持的,但只在企业版中,而不是在Express或标准版中。
My question: how to find out in C# if the connected server supports snapshot backup (is Enterprise Edition 2005 or newer or some kind of "hasFeature(...))?
我的问题是:如何在c#中找出连接服务器是否支持快照备份(企业版2005或更新还是某种“hasFeature(…)”)?
My current solution puts a try catch around the following code.
我现在的解决方案将尝试捕获以下代码。
sqlCommand.CommandText = String.Format("CREATE DATABASE {0} ON " +
(NAME = {1}, FILENAME = \"{2}\" ) AS SNAPSHOT OF {1}",
databaseBackupName,
databaseName,
filenameOfDatabseBackup);
sqlCommand.ExecuteNonQuery();
If I catch a SqlException
I assume there is no support on the connected server.
如果捕获了SqlException,则假定连接服务器上没有支持。
But maybe there could be other reasons to fail although the database supports snapshots (i.e. something is locked, connection is broken, ...)
但是,尽管数据库支持快照(例如,某些东西被锁定,连接被破坏,…),但是可能还有其他原因导致失败。
The ideal solution would be some sqlCommand.ExecuteNonQuery()
to find out if the feature is supported.
理想的解决方案是一些sqlCommand.ExecuteNonQuery(),以查明该特性是否被支持。
The second best is if I had to include some extra dll that can find it (?sqldmo?) but this would create an additional dependency to the project.
第二个好处是,如果我必须包含一些可以找到它的额外dll (?sqldmo?),那么这将创建对项目的附加依赖项。
The third best would be some kind of exception handling.
第三个最佳选择是某种异常处理。
1 个解决方案
#1
5
You could certainly do something like this:
你当然可以这样做:
SELECT
SERVERPROPERTY('productversion') as 'Product Version',
SERVERPROPERTY('engineedition') as 'Engine Edition'
The Product Version
will give you a string like this: 10.50.1600.1
. SQL Server 2005 is version 9, so anything that starts with 9., 09.
or 10., 11.
will be fine.
产品版本将提供如下字符串:10.50.1600.1。SQL Server 2005是版本9,所以任何以9开头的东西都可以。,09年。或10。11。会没事的。
The Engine Edition
gives you an INT
(1 = personal/MSDE/Express, 2 = standard, 3 = enterprise/developer).
引擎版给您一个INT (1 = personal/MSDE/Express, 2 =标准,3 =企业/开发人员)。
#1
5
You could certainly do something like this:
你当然可以这样做:
SELECT
SERVERPROPERTY('productversion') as 'Product Version',
SERVERPROPERTY('engineedition') as 'Engine Edition'
The Product Version
will give you a string like this: 10.50.1600.1
. SQL Server 2005 is version 9, so anything that starts with 9., 09.
or 10., 11.
will be fine.
产品版本将提供如下字符串:10.50.1600.1。SQL Server 2005是版本9,所以任何以9开头的东西都可以。,09年。或10。11。会没事的。
The Engine Edition
gives you an INT
(1 = personal/MSDE/Express, 2 = standard, 3 = enterprise/developer).
引擎版给您一个INT (1 = personal/MSDE/Express, 2 =标准,3 =企业/开发人员)。