private StorageEmulatorUpdatableConfiguration ProbeInstanceAndUpdate(string instanceName) { StorageEmulatorUpdatableConfiguration storageEmulatorUpdatableConfiguration; if (!StorageEmulatorUpdatableConfiguration.TryGetFromUserProfile(true, out storageEmulatorUpdatableConfiguration)) { storageEmulatorUpdatableConfiguration = new StorageEmulatorUpdatableConfiguration(); } if (!string.IsNullOrEmpty(instanceName)) { this.LogMessage(Resource.UserSpecifiedInstance, new object[0]); DBProbe dBProbe = new DBProbe((string message) => this.LogMessage(message, new object[0]), (string message) => this.LogMessage(message, new object[0])); try { if (!dBProbe.ProbeInstanceWithRetry(instanceName, 20, 10)) { this.LogErrorAndThrowException(EmulatorErrorCode.UserSpecifiedSqlInstanceNotFound, null); } else { storageEmulatorUpdatableConfiguration.SqlInstance = instanceName; this.server = storageEmulatorUpdatableConfiguration.SqlInstance; storageEmulatorUpdatableConfiguration.WriteToUserProfile(); } } catch (ArgumentException argumentException) { this.LogError("SQL instance name is rejected as malformed: {0}", new object[] { instanceName }); this.LogErrorAndThrowException(EmulatorErrorCode.UserSpecifiedSqlInstanceNotFound, null); } } return(storageEmulatorUpdatableConfiguration); }
private StorageEmulatorUpdatableConfiguration AutoDetectAndUpdate() { StorageEmulatorUpdatableConfiguration storageEmulatorUpdatableConfiguration; if (!StorageEmulatorUpdatableConfiguration.TryGetFromUserProfile(true, out storageEmulatorUpdatableConfiguration)) { storageEmulatorUpdatableConfiguration = new StorageEmulatorUpdatableConfiguration(); } this.LogMessage(Resource.LocalDBCheckForInstall, new object[0]); DBProbe dBProbe = new DBProbe((string message) => this.LogMessage(message, new object[0]), (string message) => this.LogMessage(message, new object[0])); string str = this.CheckForLocalDB(); if (str == null) { this.LogMessage(Resource.LocalDBInstallNotFound, new object[0]); try { if (!dBProbe.ProbeInstance("localhost\\SQLExpress", 2)) { storageEmulatorUpdatableConfiguration.SqlInstance = string.Empty; } else { storageEmulatorUpdatableConfiguration.SqlInstance = "localhost\\SQLExpress"; } } catch (ArgumentException argumentException) { this.LogError("SQL default instance name was rejected: {0}", new object[] { "localhost\\SQLExpress" }); storageEmulatorUpdatableConfiguration.SqlInstance = string.Empty; } } else { try { this.LogMessage(Resource.LocalDBInstallFound, new object[0]); if (!dBProbe.ProbeInstanceWithRetry(str, 20, 10)) { storageEmulatorUpdatableConfiguration.SqlInstance = string.Empty; this.LogError(Resource.LocalDBInstalledButNotRunning, new object[0]); } else { storageEmulatorUpdatableConfiguration.SqlInstance = str; } } catch (ArgumentException argumentException1) { this.LogError("LocalDB default instance name was rejected: {0}", new object[] { str }); storageEmulatorUpdatableConfiguration.SqlInstance = string.Empty; this.LogError(Resource.LocalDBInstalledButNotRunning, new object[0]); } } this.server = storageEmulatorUpdatableConfiguration.SqlInstance; storageEmulatorUpdatableConfiguration.WriteToUserProfile(); return(storageEmulatorUpdatableConfiguration); }
private string CheckForLocalDB() { DBProbe dBProbe = new DBProbe((string message) => this.LogMessage(message, new object[0]), (string message) => this.LogMessage(message, new object[0])); string str = "(localdb)\\MSSQLLocalDB"; try { if (dBProbe.ProbeInstance(str, 20)) { return(str); } } catch (ArgumentException argumentException) { this.LogError("LocalDB default instance name was rejected: {0}", new object[] { str }); } return(null); }