数据库连接串生成
摘要::如果你经常做数据库开发,那下面的东东对你会有用。
1、引用Interop.MSDASC.DLL.
2、当然写代码了:
1
using System;
2
using System.Drawing;
3
using System.Collections;
4
using System.ComponentModel;
5
using System.Windows.Forms;
6
using System.Data;
7
using System.Data.OracleClient;
8
using ADODB;
9
10
using MSDASC;
11
12
namespace 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(296, 144);
72
this.btnMake.Name = "btnMake";
73
this.btnMake.Size = new System.Drawing.Size(64, 23);
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(7, 4);
81
this.tbResult.Multiline = true;
82
this.tbResult.Name = "tbResult";
83
this.tbResult.Size = new System.Drawing.Size(355, 128);
84
this.tbResult.TabIndex = 1;
85
this.tbResult.Text = "";
86
//
87
// DBCharacterString
88
//
89
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
90
this.BackColor = System.Drawing.SystemColors.ControlDark;
91
this.ClientSize = new System.Drawing.Size(368, 172);
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

浙公网安备 33010602011771号