private void btnOK_Click(object sender, EventArgs e) { try { IPropertySet connectionProperties = this.method_1(true); if (connectionProperties != null) { string path = Environment.SystemDirectory.Substring(0, 2) + @"Users\Administrator\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\"; string str2 = RegistryTools.GetRegistryKey("HKEY_CURRENT_USER", @"Software\ESRI\Desktop10.2\CoreRuntime\Locator\Settings", "LocatorDirectory"); if (!string.IsNullOrEmpty(str2) && ((str2.IndexOf(@"Locators\", StringComparison.OrdinalIgnoreCase) > 0) && (str2.IndexOf("ArcCatalog", StringComparison.OrdinalIgnoreCase) == -1))) { path = str2.Replace("Locators", "ArcCatalog"); } if (Directory.Exists(path)) { string str3 = this.txtDatabaseInstace.Text.Trim(); if (str3 == ".") { str3 = "local-"; } if (str3.IndexOf(@"\") != -1) { str3 = str3.Replace(@"\", "_"); } if (this.cboDatabase.Text.Length > 0) { str3 = str3 + "-" + this.cboDatabase.Text; } str3 = str3 + "-" + this.cboServerType.Text; string str4 = path + "连接到" + str3 + ".sde"; str4 = this.method_2(str4); this.ConnectionPath = str4; ((IWorkspaceFactory) Activator.CreateInstance( System.Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory"))).Create(path, Path.GetFileName(str4), connectionProperties, 0); base.DialogResult = DialogResult.OK; } } } catch (Exception exception) { if (exception is COMException) { uint errorCode = (uint)(exception as COMException).ErrorCode; if ((errorCode == 2147751273) || (errorCode == 2147751169)) { MessageBox.Show("无法连接到空间数据库,请检查配置参数是否正确!", "测试连接"); } else if (errorCode == 2147751274) { MessageBox.Show("该服务器上的SDE没有启动,请启动服务器上的SDE后在测试!", "测试连接"); } else if (errorCode == 2147500037) { MessageBox.Show("无法连接到空间数据库,请检查配置参数是否正确!", "测试连接"); } else { MessageBox.Show(exception.Message, "测试连接"); } } else { MessageBox.Show(exception.Message, "测试连接"); } } }