本文整理汇总了C#中System.Data.SqlClient.SqlConnectionStringBuilder.Split方法的典型用法代码示例。如果您正苦于以下问题:C# SqlConnectionStringBuilder.Split方法的具体用法?C# SqlConnectionStringBuilder.Split怎么用?C# SqlConnectionStringBuilder.Split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlConnectionStringBuilder
的用法示例。
在下文中一共展示了SqlConnectionStringBuilder.Split方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckSqlServer
public static bool CheckSqlServer()
{
if (!CheckSqlServerState.Value)
{
return true;
}
try
{
using (new ProfileSection("Check SQL Server"))
{
var profile = ProfileManager.Profile;
Assert.IsNotNull(profile, "Profile is unavailable");
var ds = new SqlConnectionStringBuilder(profile.ConnectionString).DataSource;
var arr = ds.Split('\\');
var name = arr.Length == 2 ? arr[1] : String.Empty;
var serviceName = GetSqlServerServiceName(profile.ConnectionString);
if (String.IsNullOrEmpty(serviceName))
{
WindowHelper.HandleError("The {0} instance of SQL Server cannot be reached".FormatWith(ds), false);
return ProfileSection.Result(false);
}
ServiceController[] serviceControllers = ServiceController.GetServices();
ServiceController server = (!String.IsNullOrEmpty(name) ? serviceControllers.FirstOrDefault(s => s.ServiceName.EqualsIgnoreCase(name)) : null) ??
serviceControllers.FirstOrDefault(
s => s.ServiceName.EqualsIgnoreCase(serviceName)) ??
serviceControllers.FirstOrDefault(s => s.ServiceName.EqualsIgnoreCase(serviceName));
Assert.IsNotNull(server, "Cannot find the " + (name.EmptyToNull() ?? "default") + " sql server instance");
var result = CheckSqlServer(server);
return ProfileSection.Result(result);
}
}
catch (Exception ex)
{
Log.Warn(ex, "Failed to check SQL Server state");
return ProfileSection.Result(true);
}
}
示例2: GetProductName
protected string GetProductName([NotNull] string instanceName)
{
Assert.ArgumentNotNull(instanceName, "instanceName");
string value = new SqlConnectionStringBuilder(this.Value).InitialCatalog;
string[] arr = value.Split('_');
return arr.Length == 2 ? arr[0].TrimStart(instanceName) : string.Empty;
}