数据库连接串生成

摘要::如果你经常做数据库开发,那下面的东东对你会有用。


1、引用Interop.MSDASC.DLL. 
                                                                                                                                                

2、当然写代码了:

  1using System;
  2using System.Drawing;
  3using System.Collections;
  4using System.ComponentModel;
  5using System.Windows.Forms;
  6using System.Data;
  7using System.Data.OracleClient;
  8using ADODB;
  9
 10using MSDASC;
 11
 12namespace Data_Link_Properties
 13{
 14    /// <summary>
 15    /// Form1 的摘要说明。
 16    /// </summary>

 17    public class DBCharacterString : System.Windows.Forms.Form
 18    {
 19        private MSDASC.DataLinksClass _dlc;
 20        private IntPtr _ptr1;
 21        private System.Windows.Forms.TextBox tbResult;
 22        private System.Windows.Forms.Button btnMake;
 23
 24        /// <summary>
 25        /// 必需的设计器变量。
 26        /// </summary>

 27        private System.ComponentModel.Container components = null;
 28
 29        public DBCharacterString()
 30        {
 31            //
 32            // Windows 窗体设计器支持所必需的
 33            //
 34            InitializeComponent();
 35
 36            //
 37            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
 38            //
 39        }

 40
 41        /// <summary>
 42        /// 清理所有正在使用的资源。
 43        /// </summary>

 44        protected override void Dispose( bool disposing )
 45        {
 46            if( disposing )
 47            {
 48                if (components != null
 49                {
 50                    components.Dispose();
 51                }

 52            }

 53            base.Dispose( disposing );
 54        }

 55
 56        #region Windows 窗体设计器生成的代码
 57        /// <summary>
 58        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
 59        /// 此方法的内容。
 60        /// </summary>

 61        private void InitializeComponent()
 62        {
 63            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(DBCharacterString));
 64            this.btnMake = new System.Windows.Forms.Button();
 65            this.tbResult = new System.Windows.Forms.TextBox();
 66            this.SuspendLayout();
 67            // 
 68            // btnMake
 69            // 
 70            this.btnMake.FlatStyle = System.Windows.Forms.FlatStyle.System;
 71            this.btnMake.Location = new System.Drawing.Point(296144);
 72            this.btnMake.Name = "btnMake";
 73            this.btnMake.Size = new System.Drawing.Size(6423);
 74            this.btnMake.TabIndex = 0;
 75            this.btnMake.Text = "生成";
 76            this.btnMake.Click += new System.EventHandler(this.btnMake_Click);
 77            // 
 78            // tbResult
 79            // 
 80            this.tbResult.Location = new System.Drawing.Point(74);
 81            this.tbResult.Multiline = true;
 82            this.tbResult.Name = "tbResult";
 83            this.tbResult.Size = new System.Drawing.Size(355128);
 84            this.tbResult.TabIndex = 1;
 85            this.tbResult.Text = "";
 86            // 
 87            // DBCharacterString
 88            // 
 89            this.AutoScaleBaseSize = new System.Drawing.Size(614);
 90            this.BackColor = System.Drawing.SystemColors.ControlDark;
 91            this.ClientSize = new System.Drawing.Size(368172);
 92            this.Controls.Add(this.tbResult);
 93            this.Controls.Add(this.btnMake);
 94            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
 95            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
 96            this.Name = "DBCharacterString";
 97            this.Text = "数据库连接串生成器";
 98            this.ResumeLayout(false);
 99
100        }

101        #endregion

102
103        /// <summary>
104        /// 应用程序的主入口点。
105        /// </summary>

106        [STAThread]
107        static void Main() 
108        {
109            Application.Run(new DBCharacterString());
110        }

111
112        #region  事件处理
113        private void btnMake_Click(object sender, System.EventArgs e)
114        {
115            ADODB.Connection conn;
116            _dlc = new DataLinksClass();
117            _ptr1 = this.Handle;
118            _dlc.hWnd = _ptr1.ToInt32();
119            conn = _dlc.PromptNew() as ADODB.Connection;
120            if( conn != null )
121            {
122                this.tbResult.Text = conn.ConnectionString;
123            }

124        }

125        #endregion

126
127    }

128}

129
原文地址:https://www.cnblogs.com/mohai/p/148110.html