• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

打造自己的C#WinForm应用程序的SQLServer连接配置界面

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
在C# WinForm 应用程序非常需要一个 SQL Server 连接配置界面,许多时候,因 SQL Server 服务器地址变更或 数据库登录账户 变更引起的连接失败等情况,客户就可能打电话“找麻烦”。既然这样,还不如提供一个可视化的配置界面,并在用户手册中说明使用方法,尽可能避免这种小问题带来的烦恼。为此,我将自己无聊时写的连接配置源码贴出来给初学者参考,以备不时之需!
想必大家都很熟悉VS服务器资源管理器中的【添加连接】对话框吧!下面是它的截图:
再看看我模仿这个对话框打造的WinForm程序SQL Server 连接配置界面:
呵呵!有几分相似吧!需要的朋友可以参考下面的源码。这份源码是完整的,粘贴到VS中即可使用。
窗体源码:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.IO;
  8. using System.Windows.Forms;
  9. using System.Data.Sql;
  10. using System.Data.SqlClient;
  11. using System.Configuration;
  12. namespace CodingMouse.CMCSharpSDK.UI.Forms
  13. {
  14.     /// <summary>
  15.     /// 数据库连接配置界面
  16.     /// </summary>
  17.     public partial class frmConnectionConfig : Form
  18.     {
  19.         #region Private Members
  20.         /// <summary>
  21.         /// SQL Server 连接字符串创建者对象
  22.         /// </summary>
  23.         SqlConnectionStringBuilder _connectionStringBuilder = null;
  24.         /// <summary>
  25.         /// 当前应用程序名称
  26.         /// </summary>
  27.         string _applicationName;
  28.         #endregion
  29.         #region Private Methods
  30.         /// <summary>
  31.         /// 获取 本地网络所有 SQL Server 实例(数据源)
  32.         /// </summary>
  33.         private void GetSqlDataSource()
  34.         {
  35.             // 显示提示信息
  36.             string msg = "正在获取本地网络所有 SQL Server 服务器信息 ...";
  37.             this.toolTip.ToolTipIcon = ToolTipIcon.Info;
  38.             this.toolTip.ToolTipTitle = "请稍候...";
  39.             Point showLocation = new Point(
  40.                 this.lblServer.Left + 2,
  41.                 this.lblServer.Top + this.lblServer.Height);
  42.             this.toolTip.Show(msg, this, showLocation, 1000);
  43.             // 创建 提供了一种枚举本地网络内的所有可用 SQL Server 实例的机制 的实例
  44.             SqlDataSourceEnumerator sdsEnum = SqlDataSourceEnumerator.Instance;
  45.             // 调用 检索包含有关所有可见 SQL Server 2000 或 SQL Server 2005 实例的信息的 DataTable 的方法
  46.             DataTable serverDt = sdsEnum.GetDataSources();
  47.             // 创建新列以拼接 ServerName 以及 InstanceName 列的内容(以此构建连接字符串的 Server / Data Source 项)
  48.             DataColumn dcDataSource = new DataColumn("SqlDataSourceName"typeof(string));
  49.             // 将新列添加到 DataTable
  50.             serverDt.Columns.Add(dcDataSource);
  51.             // 创建新列以用中文方式显示 IsClustered 列内容
  52.             DataColumn dcIsClustered = new DataColumn("IsClusteredCHS"typeof(string));
  53.             // 将新列添加到 DataTable
  54.             serverDt.Columns.Add(dcIsClustered);
  55.             // 遍历 DataTable 并给新列赋予拼接后的值
  56.             foreach (DataRow dataRow in serverDt.Rows)
  57.             {
  58.                 if (!string.IsNullOrEmpty(Convert.ToString(dataRow["InstanceName"])))
  59.                     dataRow["SqlDataSourceName"] = string.Format(@"{0}/{1}",
  60.                         Convert.ToString(dataRow["ServerName"]),
  61.                         Convert.ToString(dataRow["InstanceName"]));
  62.                 else
  63.                     dataRow["SqlDataSourceName"] = string.Format(@"{0}",
  64.                         Convert.ToString(dataRow["ServerName"]));
  65.                 dataRow["IsClusteredCHS"] = 
  66.                     (Convert.ToString(dataRow["IsClustered"]).Trim().ToUpper() == "NO")
  67.                     ? "否" : ((Convert.ToString(dataRow["IsClustered"]).Trim().ToUpper() == "YES"
  68.                     ? "是" : dataRow["IsClustered"]);
  69.             }
  70.             // 如果包含数据行
  71.             if (serverDt.Rows.Count > 0)
  72.             {
  73.                 // 创建窗体数据源封装类实例并封装 DataTable
  74.                 BindingSource source = new BindingSource();
  75.                 source.DataSource = serverDt;
  76.                 // 设置 ComboBox 数据源
  77.                 this.cboSqlDataSource.DataSource = source;
  78.                 this.cboSqlDataSource.DisplayMember = "SqlDataSourceName";
  79.                 this.cboSqlDataSource.ValueMember = "SqlDataSourceName";
  80.                 // 设置 DataGridView 数据源
  81.                 this.dgvServerInfo.DataSource = source;
  82.                 // 设置中文列名
  83.                 this.dgvServerInfo.Columns["SqlDataSourceName"].HeaderText = "服务器名";
  84.                 this.dgvServerInfo.Columns["SqlDataSourceName"].DisplayIndex = 0;
  85.                 this.dgvServerInfo.Columns["ServerName"].HeaderText = "服务器物理名称";
  86.                 this.dgvServerInfo.Columns["ServerName"].DisplayIndex = 1;
  87.                 this.dgvServerInfo.Columns["ServerName"].Visible = false;
  88.                 this.dgvServerInfo.Columns["InstanceName"].HeaderText = "实例名";
  89.                 this.dgvServerInfo.Columns["InstanceName"].DisplayIndex = 2;
  90.                 this.dgvServerInfo.Columns["InstanceName"].Visible = false;
  91.                 this.dgvServerInfo.Columns["IsClustered"].HeaderText = "群集信息";
  92.                 this.dgvServerInfo.Columns["IsClustered"].DisplayIndex = 3;
  93.                 this.dgvServerInfo.Columns["IsClustered"].Visible = false;
  94.                 this.dgvServerInfo.Columns["IsClusteredCHS"].HeaderText = "属于群集";
  95.                 this.dgvServerInfo.Columns["IsClusteredCHS"].DisplayIndex = 4;
  96.                 this.dgvServerInfo.Columns["Version"].HeaderText = "版本";
  97.                 this.dgvServerInfo.Columns["Version"].DisplayIndex = 5;
  98.             }
  99.         }
  100.         /// <summary>
  101.         /// 获取当前服务器上所有数据库名称
  102.         /// </summary>
  103.         private void GetDataBaseName()
  104.         {
  105.             // 显示提示信息
  106.             string msg = string.Format("正在获取服务器 [{0}] 上的数据库信息 ...", cboSqlDataSource.Text.Trim());
  107.             this.toolTip.ToolTipIcon = ToolTipIcon.Info;
  108.             this.toolTip.ToolTipTitle = "请稍候...";
  109.             Point showLocation = new Point(
  110.                 this.lblServer.Left + 2,
  111.                 this.lblServer.Top + this.lblServer.Height);
  112.             this.toolTip.Show(msg, this, showLocation, 1000);
  113.             // 查询服务器上所有数据库的 SQL 查询命令
  114.             string sqlTxt = "Select [Name] From [SysDatabases] Order By [Name]";
  115.             // 保存结果的 DataTable
  116.             DataTable dataBaseDt = new DataTable();
  117.             // 创建连接对象
  118.             using (SqlConnection con = new SqlConnection(GetConnectionString()))
  119.             {
  120.                 // 执行查询
  121.                 try
  122.                 {
  123.                     // 创建适配器对象
  124.                     using (SqlDataAdapter adp = new SqlDataAdapter(sqlTxt, con))
  125.                     {
  126.                         // 将查询结果填充到 DataTable
  127.                         adp.Fill(dataBaseDt);
  128.                     }
  129.                 }
  130.                 catch { }  // 不弹出异常消息
  131.             }
  132.             // 如果 DataTable 包含数据行
  133.             if (dataBaseDt.Rows.Count > 0)
  134.             {
  135.                 // 创建窗体数据绑定对象
  136.                 BindingSource source = new BindingSource();
  137.                 source.DataSource = dataBaseDt;
  138.                 // 将结果绑定到数据库列表
  139.                 cboDataBaseName.DataSource = source;
  140.                 cboDataBaseName.DisplayMember = "Name";
  141.                 cboDataBaseName.ValueMember = "Name";
  142.             }
  143.             else
  144.             {
  145.                 // 移除数据库列表
  146.                 cboDataBaseName.DataSource = null;
  147.             }
  148.         }
  149.         /// <summary>
  150.         /// 获取连接字符串
  151.         /// </summary>
  152.         private string GetConnectionString()
  153.         {
  154.             // 重新创建连接字符串创建者
  155.             _connectionStringBuilder = new SqlConnectionStringBuilder();
  156.             // 获取服务器名称
  157.             if (!string.IsNullOrEmpty(cboSqlDataSource.Text.Trim()))
  158.                 _connectionStringBuilder.DataSource = cboSqlDataSource.Text.Trim();
  159.             // 获取登录类型
  160.             if (rdoValidateBySQLServer.Checked)
  161.             {
  162.                 if (!string.IsNullOrEmpty(txtUserName.Text.Trim()))
  163.                     _connectionStringBuilder.UserID = txtUserName.Text.Trim();
  164.                 if (!string.IsNullOrEmpty(txtPassword.Text.Trim()))
  165.                     _connectionStringBuilder.Password = txtPassword.Text.Trim();
  166.             }
  167.             // 获取默认数据库
  168.             if (!string.IsNullOrEmpty(cboDataBaseName.Text.Trim())
  169.                 || !string.IsNullOrEmpty(txtDataBaseFilePath.Text.Trim())
  170.                 || !string.IsNullOrEmpty(txtLogicalName.Text.Trim()))
  171.             {
  172.                 // 如果是附加一个数据库文件
  173.                 if (rdoAttachADataBaseFile.Checked)
  174.                 {
  175.                     _connectionStringBuilder.AttachDBFilename = txtDataBaseFilePath.Text.Trim();
  176.                     _connectionStringBuilder.InitialCatalog = txtLogicalName.Text.Trim();
  177.                 }
  178.                 else
  179.                     _connectionStringBuilder.InitialCatalog = cboDataBaseName.Text.Trim();
  180.             }
  181.             // 调整连接字符串
  182.             if (rdoValidateByWindows.Checked)
  183.                 _connectionStringBuilder.IntegratedSecurity = true;
  184.             // 返回连接字符串
  185.             return _connectionStringBuilder.ConnectionString;
  186.         }
  187.         #endregion
  188.         #region Public Methods
  189.         /// <summary>
  190.         /// 无参构造
  191.         /// </summary>
  192.         public frmConnectionConfig(string applicationName)
  193.         {
  194.             // 构建设计器控件
  195.             InitializeComponent();
  196.             // 保存当前应用程序名称
  197.             _applicationName = applicationName;
  198.             // 创建连接字符串创建者
  199.             _connectionStringBuilder = new SqlConnectionStringBuilder();
  200.             _connectionStringBuilder.IntegratedSecurity = true;
  201.             //_connectionStringBuilder.ApplicationName = _applicationName;
  202.             //_connectionStringBuilder.AsynchronousProcessing = true;
  203.             //_connectionStringBuilder.Encrypt = true;
  204.         } 
  205.         #endregion
  206.         #region Event Handlers
  207.         /// <summary>
  208.         /// 数据源 列表下拉事件
  209.         /// </summary>
  210.         /// <param name="sender"></param>
  211.         /// <param name="e"></param>
  212.         private void cboSqlDataSource_DropDown(object sender, EventArgs e)
  213.         {
  214.             // 如果 数据源 列表条目为空
  215.             if (cboSqlDataSource.Items.Count == 0)
  216.             {
  217.                 // 获取 本地网络所有 SQL Server 实例(数据源)
  218.                 GetSqlDataSource();
  219.             }
  220.         }
  221.         /// <summary>
  222.         /// 数据库 列表获得焦点事件
  223.         /// </summary>
  224.         /// <param name="sender"></param>
  225.         /// <param name="e"></param>
  226.         private void cboDataBaseName_Enter(object sender, EventArgs e)
  227.         {
  228.             // 获取当前服务器上所有数据库名称
  229.             GetDataBaseName();
  230.         }
  231.         /// <summary>
  232.         /// 选择选项卡页事件
  233.         /// </summary>
  234.         /// <param name="sender"></param>
  235.         /// <param name="e"></param>
  236.         private void tcServerInfo_Selecting(object sender, TabControlCancelEventArgs e)
  237.         {
  238.             // 如果 数据源 列表条目为空
  239.             if (cboSqlDataSource.Items.Count == 0 && e.TabPage == tpServerInfo)
  240.             {
  241.                 // 获取 本地网络所有 SQL Server 实例(数据源)
  242.                 GetSqlDataSource();
  243.             }
  244.         }
  245.         /// <summary>
  246.         /// [刷新]按钮点击事件
  247.         /// </summary>
  248.         /// <param name="sender"></param>
  249.         /// <param name="e"></param>
  250.         private void btnRefresh_Click(object sender, EventArgs e)
  251.         {
  252.             // 获取 本地网络所有 SQL Server 实例(数据源)
  253.             GetSqlDataSource();
  254.         }
  255.         /// <summary>
  256.         /// [使用 SQL Server 身份验证]单选按钮 Checked 属性更改事件
  257.         /// </summary>
  258.         /// <param name="sender"></param>
  259.         /// <param name="e"></param>
  260.         private void rdoValidateBySQLServer_CheckedChanged(object sender, EventArgs e)
  261.         {
  262.             if (rdoValidateBySQLServer.Checked)
  263.             {
  264.                 _connectionStringBuilder.IntegratedSecurity = false;
  265.                 lblUserName.Enabled = true;
  266.                 txtUserName.Enabled = true;
  267.                 lblPassword.Enabled = true;
  268.                 txtPassword.Enabled = true;
  269.                 if (!string.IsNullOrEmpty(txtUserName.Text.Trim()))
  270.                     gbConnectToADataBase.Enabled = true;
  271.                 else
  272.                     gbConnectToADataBase.Enabled = false;
  273.             }
  274.             else
  275.             {
  276.                 _connectionStringBuilder.IntegratedSecurity = true;
  277.                 lblUserName.Enabled = false;
  278.                 txtUserName.Enabled = false;
  279.                 lblPassword.Enabled = false;
  280.                 txtPassword.Enabled = false;
  281.                 if (!string.IsNullOrEmpty(cboSqlDataSource.Text.Trim()))
  282.                     gbConnectToADataBase.Enabled = true;
  283.                 else
  284.                     gbConnectToADataBase.Enabled = false;
  285.             }
  286.         }
  287.         /// <summary>
  288.         /// [附加一个数据库文件]单选按钮 Checked 属性更改事件
  289.         /// </summary>
  290.         /// <param name="sender"></param>
  291.         /// <param name="e"></param>
  292.         private void rdoAttachADataBaseFile_CheckedChanged(object sender, EventArgs e)
  293.         {
  294.             if (rdoAttachADataBaseFile.Checked)
  295.             {
  296.                 cboDataBaseName.Enabled = false;
  297.                 txtDataBaseFilePath.Enabled = true;
  298.                 btnBrowse.Enabled = true;
  299.                 lblLogicalName.Enabled = true;
  300.                 txtLogicalName.Enabled = true;
  301.             }
  302.             else
  303.             {
  304.                 cboDataBaseName.Enabled = true;
  305.                 txtDataBaseFilePath.Enabled = false;
  306.                 btnBrowse.Enabled = false;
  307.                 lblLogicalName.Enabled = false;
  308.                 txtLogicalName.Enabled = false;
  309.             }
  310.         }
  311.         
  312.         /// <summary>
  313.         /// 数据源 列表 Text 值更改事件
  314.         /// </summary>
  315.         /// <param name="sender"></param>
  316.         /// <param name="e"></param>
  317.         private void cboSqlDataSource_TextChanged(object sender, EventArgs e)
  318.         {
  319.             if (!string.IsNullOrEmpty(cboSqlDataSource.Text.Trim())
  320.                 && _connectionStringBuilder.IntegratedSecurity == true
  321.                 || !string.IsNullOrEmpty(txtUserName.Text.Trim())
  322.                 && _connectionStringBuilder.IntegratedSecurity == false)
  323.             {
  324.                 gbConnectToADataBase.Enabled = true;
  325.                 btnOK.Enabled = true;
  326.             }
  327.             else
  328.             {
  329.                 gbConnectToADataBase.Enabled = false;
  330.                 btnOK.Enabled = false;
  331.             }
  332.         }
  333.         /// <summary>
  334.         /// [用户名]文本框文本更改事件
  335.         /// </summary>
  336.         /// <param name="sender"></param>
  337.         /// <param name="e"></param>
  338.         private void txtUserName_TextChanged(object sender, EventArgs e)
  339.         {
  340.             if (!string.IsNullOrEmpty(txtUserName.Text.Trim()))
  341.                 gbConnectToADataBase.Enabled = true;
  342.             else
  343.                 gbConnectToADataBase.Enabled = false;
  344.         }
  345.         /// <summary>
  346.         /// [测试连接]按钮点击事件
  347.         /// </summary>
  348.         /// <param name="sender"></param>
  349.         /// <param name="e"></param>
  350.         private void btnTestConnection_Click(object sender, EventArgs e)
  351.         {
  352.             if (!string.IsNullOrEmpty(cboSqlDataSource.Text.Trim()))
  353.             {
  354.                 // 创建连接对象
  355.                 using (SqlConnection con = new SqlConnection(GetConnectionString()))
  356.                 {
  357.                     try
  358.                     {
  359.                         // 打开数据库连接
  360.                         con.Open();
  361.                         // 给出用户提示
  362.                         MessageBox.Show(
  363.                             "测试连接成功。",
  364.                             this.Text,
  365.                             MessageBoxButtons.OK,
  366.                             MessageBoxIcon.Information);
  367.                     }
  368.                     catch (Exception ex)
  369.                     {
  370.                         MessageBox.Show(
  371.                         ex.Message,
  372.                         this.Text,
  373.                         MessageBoxButtons.OK,
  374.                         MessageBoxIcon.Error);
  375.                     }
  376.                     finally
  377.                     {
  378.                         // 关闭数据库连接
  379.                         con.Close();
  380.                     }
  381.                 }
  382.             }
  383.             else
  384.             {
  385.                 MessageBox.Show(
  386.                     "无法测试此连接,因为没有指定服务器名称。",
  387.                     this.Text,
  388.                     MessageBoxButtons.OK,
  389.                     MessageBoxIcon.Error);
  390.             }
  391.         }
  392.         /// <summary>
  393.         /// [确定]按钮点击事件 
  394.         /// </summary>
  395.         /// <param name="sender"></param>
  396.         /// <param name="e"></param>
  397.         private void btnOK_Click(object sender, EventArgs e)
  398.         {
  399.             try
  400.             {
  401.                 // 创建应用程序配置文件
  402.                 string configFilePath = string.Format(@"{0}.config", Application.ExecutablePath);
  403.                 Configuration configuration = null;
  404.                 if (!File.Exists(configFilePath))
  405.                 {
  406.                     FileStream fs = null;
  407.                     try
  408.                     {
  409.                         fs = new FileStream(configFilePath, FileMode.CreateNew);
  410.                         fs.SetLength(0);
  411.                     }
  412.                     catch { }   // 不弹出异常提示
  413.                     finally
  414.                     {
  415.                         fs.Close();
  416.                     }
  417.                 }
  418.                 configuration = ConfigurationManager.OpenExeConfiguration(configFilePath);
  419.                 // configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  420.                 // 遍历检验 ConnectionType 项是否存在
  421.                 bool appSettingsExist = false;
  422.                 foreach (KeyValueConfigurationElement element in configuration.AppSettings.Settings)
  423.                 {
  424.                     // 如果存在
  425.                     if (element.Key == "ConnectionType")
  426.                     {
  427.                         // 标识存在
  428.                         appSettingsExist = true;
  429.                         break;
  430.                     }
  431.                 }
  432.                 // 如果存在
  433.                 if (appSettingsExist)
  434.                     // 修改配置节点
  435.                     configuration.AppSettings.Settings["ConnectionType"].Value = "SQLSERVER";
  436.                 else
  437.                     // 添加配置节点
  438.                     configuration.AppSettings.Settings.Add("ConnectionType""SQLSERVER");
  439.                 // 遍历检验 SQLSERVER 项是否存在
  440.                 bool connectionStringExist = false;
  441.                 foreach (ConnectionStringSettings setting in configuration.ConnectionStrings.ConnectionStrings)
  442.                 {
  443.                     // 如果存在
  444.                     if (setting.Name == "SQLSERVER")
  445.                     {
  446.                         // 标识存在
  447.                         connectionStringExist = true;
  448.                     }
  449.                 }
  450.                 // 如果存在
  451.                 if (connectionStringExist)
  452.                 {
  453.                     // 修改配置节点
  454.                     configuration.ConnectionStrings.ConnectionStrings["SQLSERVER"].ConnectionString =
  455.                         GetConnectionString();
  456.                     configuration.ConnectionStrings.ConnectionStrings["SQLSERVER"].ProviderName =
  457.                         "System.Data.SqlClient";
  458.                 }
  459.                 else
  460.                 {
  461.                     // 添加连接字符串节点
  462.                     configuration.ConnectionStrings.ConnectionStrings.Add(
  463.                         new ConnectionStringSettings(
  464.                         "SQLSERVER",
  465.                         GetConnectionString(),
  466.                         "System.Data.SqlClient"));
  467.                 }
  468.                 // 保存配置
  469.                 configuration.SaveAs(
  470.                     string.Format(@"{0}.config", Application.ExecutablePath.Replace(".EXE"".exe")),
  471.                     ConfigurationSaveMode.Minimal);
  472.                 // 关闭窗体
  473.                 this.Close();
  474.             }
  475.             catch (Exception ex)
  476.             {
  477.                 MessageBox.Show(
  478.                     string.Format("保存数据库连接配置时发生以下错误:/r/n/r/n{0}", ex.Message),
  479.                     this.Text,
  480.                     MessageBoxButtons.OK,
  481.                     MessageBoxIcon.Error);
  482.             }
  483.         }
  484.         /// <summary>
  485.         /// [取消]按钮点击事件
  486.         /// </summary>
  487.         /// <param name="sender"></param>
  488.         /// <param name="e"></param>
  489.         private void btnCancel_Click(object sender, EventArgs e)
  490.         {
  491.             this.Close();
  492.         }
  493.         /// <summary>
  494.         /// [浏览]按钮点击事件
  495.         /// </summary>
  496.         /// <param name="sender"></param>
  497.         /// <param name="e"></param>
  498.         private void btnBrowse_Click(object sender, EventArgs e)
  499.         {
  500.             OpenFileDialog ofDlg = new OpenFileDialog();
  501.             ofDlg.Title = "选择 SQL Server 数据库文件";
  502.             ofDlg.Filter = "Microsoft SQL Server 数据库(*.mdf)|*.mdf|所有文件(*.*)|*.*";
  503.             ofDlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  504.             DialogResult result = ofDlg.ShowDialog(this);
  505.             if (result == DialogResult.OK)
  506.                 txtDataBaseFilePath.Text = ofDlg.FileName;
  507.         }
  508.         /// <summary>
  509.         /// [获取连接字符串]按钮点击事件
  510.         /// </summary>
  511.         /// <param name="sender"></param>
  512.         /// <param name="e"></param>
  513.         private void btnGetConnectionString_Click(object sender, EventArgs e)
  514.         {
  515.             this.txtConnectionString.Text = GetConnectionString();
  516.         }
  517.         #endregion
  518.     }
  519. }

设计器源码:

 

 

  1. namespace CodingMouse.CMCSharpSDK.UI.Forms
  2. {
  3.     partial class frmConnectionConfig
  4.     {
  5.         /// <summary>
  6.         /// 必需的设计器变量。
  7.         /// </summary>
  8.         private System.ComponentModel.IContainer components = null;
  9.         /// <summary>
  10.         /// 清理所有正在使用的资源。
  11.         /// </summary>
  12.         /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
  13.         protected override void Dispose(bool disposing)
  14.         {
  15.             if (disposing && (components != null))
  16.             {
  17.                 components.Dispose();
  18.             }
  19.             base.Dispose(disposing);
  20.         }
  21.         #region Windows 窗体设计器生成的代码
  22.         /// <summary>
  23.         /// 设计器支持所需的方法 - 不要
  24.         /// 使用代码编辑器修改此方法的内容。
  25.         /// </summary>
  26.         private void InitializeComponent()
  27.         {
  28.             this.components = new System.ComponentModel.Container();
  29.             this.cboSqlDataSource = new System.Windows.Forms.ComboBox();
  30.             this.tcServerInfo = new System.Windows.Forms.TabControl();
  31.             this.tpConnectionInfo = new System.Windows.Forms.TabPage();
  32.             this.gbConnectToADataBase = new System.Windows.Forms.GroupBox();
  33.             this.txtLogicalName = new System.Windows.Forms.TextBox();
  34.             this.lblLogicalName = new System.Windows.Forms.Label();
  35.             this.btnBrowse = new System.Windows.Forms.Button();
  36.             this.cboDataBaseName = new System.Windows.Forms.ComboBox();
  37.             this.txtDataBaseFilePath = new System.Windows.Forms.TextBox();
  38.             this.rdoAttachADataBaseFile = new System.Windows.Forms.RadioButton();
  39.             this.rdoSelectOrEnterADataBaseName = new System.Windows.Forms.RadioButton();
  40.             this.gbLogOnToTheServer = new System.Windows.Forms.GroupBox();
  41.             this.txtPassword = new System.Windows.Forms.TextBox();
  42.             this.txtUserName = new System.Windows.Forms.TextBox();
  43.             this.lblPassword = new System.Windows.Forms.Label();
  44.             this.lblUserName = new System.Windows.Forms.Label();
  45.             this.rdoValidateBySQLServer = new System.Windows.Forms.RadioButton();
  46.             this.rdoValidateByWindows = new System.Windows.Forms.RadioButton();
  47.             this.tpServerInfo = new System.Windows.Forms.TabPage();
  48.             this.dgvServerInfo = new System.Windows.Forms.DataGridView();
  49.             this.toolTip = new System.Windows.Forms.ToolTip(this.components);
  50.             this.btnRefresh = new System.Windows.Forms.Button();
  51.             this.lblServer = new System.Windows.Forms.Label();
  52.             this.btnGetConnectionString = new System.Windows.Forms.Button();
  53.             this.btnCancel = new System.Windows.Forms.Button();
  54.             this.btnOK = new System.Windows.Forms.Button();
  55.             this.btnTestConnection = new System.Windows.Forms.Button();
  56.             this.lblSplit = new System.Windows.Forms.Label();
  57.             this.txtConnectionString = new System.Windows.Forms.TextBox();
  58.             this.tcServerInfo.SuspendLayout();
  59.             this.tpConnectionInfo.SuspendLayout();
  60.             this.gbConnectToADataBase.SuspendLayout();
  61.             this.gbLogOnToTheServer.SuspendLayout();
  62.             this.tpServerInfo.SuspendLayout();
  63.             ((System.ComponentModel.ISupportInitialize)(this.dgvServerInfo)).BeginInit();
  64.             this.SuspendLayout();
  65.             // 
  66.             // cboSqlDataSource
  67.             // 
  68.             this.cboSqlDataSource.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  69.                         | System.Windows.Forms.AnchorStyles.Right)));
  70.             this.cboSqlDataSource.FormattingEnabled = true;
  71.             this.cboSqlDataSource.Location = new System.Drawing.Point(12, 24);
  72.             this.cboSqlDataSource.Name = "cboSqlDataSource";
  73.             this.cboSqlDataSource.Size = new System.Drawing.Size(269, 20);
  74.             this.cboSqlDataSource.TabIndex = 1;
  75.             this.cboSqlDataSource.Leave += new System.EventHandler(this.cboSqlDataSource_Leave);
  76.             this.cboSqlDataSource.TextChanged += new System.EventHandler(this.cboSqlDataSource_TextChanged);
  77.             this.cboSqlDataSource.DropDown += new System.EventHandler(this.cboSqlDataSource_DropDown);
  78.             // 
  79.             // tcServerInfo
  80.             // 
  81.             this.tcServerInfo.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  82.                         | System.Windows.Forms.AnchorStyles.Right)));
  83.             this.tcServerInfo.Controls.Add(this.tpConnectionInfo);
  84.             this.tcServerInfo.Controls.Add(this.tpServerInfo);
  85.             this.tcServerInfo.HotTrack = true;
  86.             this.tcServerInfo.Location = new System.Drawing.Point(12, 50);
  87.             this.tcServerInfo.Name = "tcServerInfo";
  88.             this.tcServerInfo.SelectedIndex = 0;
  89.             this.tcServerInfo.ShowToolTips = true;
  90.             this

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#编程(七十五)----------C#使用指针发布时间:2022-07-13
下一篇:
C#对象内部属性排序测试发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap