using System using System Drawing using System Collections using Syste

  1
  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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
namespace testSQLDELETE
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class FormMain : System.Windows.Forms.Form
{
private System.Windows.Forms.Button buttonStart;
private System.Windows.Forms.Button buttonStop;
private System.Data.SqlClient.SqlCommand sqlCommand;
private System.Data.SqlClient.SqlConnection sqlConnection;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public FormMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonStart = new System.Windows.Forms.Button();
this.buttonStop = new System.Windows.Forms.Button();
this.sqlCommand = new System.Data.SqlClient.SqlCommand();
this.sqlConnection = new System.Data.SqlClient.SqlConnection();
this.SuspendLayout();
//
// buttonStart
//
this.buttonStart.Location = new System.Drawing.Point(40, 48);
this.buttonStart.Name = "buttonStart";
this.buttonStart.TabIndex = 0;
this.buttonStart.Text = "Start";
this.buttonStart.Click += new System.EventHandler(this.buttonStart_Click);
//
// buttonStop
//
this.buttonStop.Location = new System.Drawing.Point(168, 48);
this.buttonStop.Name = "buttonStop";
this.buttonStop.TabIndex = 1;
this.buttonStop.Text = "Stop";
this.buttonStop.Click += new System.EventHandler(this.buttonStop_Click);
//
// sqlCommand
//
this.sqlCommand.Connection = this.sqlConnection;
//
// sqlConnection
//
this.sqlConnection.ConnectionString = "workstation id=\"PC-NIK\";packet size=4096;integrated security=SSPI;data source=loc" +
"alhost;persist security info=False;initial catalog=LargeDB";
//
// FormMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 133);
this.Controls.Add(this.buttonStop);
this.Controls.Add(this.buttonStart);
this.Name = "FormMain";
this.Text = "Test sql msde";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new FormMain());
}
bool m_bIsActive = false;
private void buttonStart_Click(object sender, System.EventArgs e)
{
try
{
if (sqlConnection.State != ConnectionState.Open)
{
sqlConnection.Open();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
sqlCommand.CommandText = "INSERT INTO LargeData (Data) VALUES (@Data)";
sqlCommand.CommandType = CommandType.Text;
Cursor = Cursors.WaitCursor;
m_bIsActive = true;
string strRandom = "";
while (m_bIsActive)
{
try
{
strRandom = RandomString(200, false);
sqlCommand.Parameters.Clear();
sqlCommand.Parameters.Add("@Data", strRandom);
sqlCommand.ExecuteNonQuery();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
m_bIsActive = false;
}
Application.DoEvents();
}
Cursor = Cursors.Default;
}
private void buttonStop_Click(object sender, System.EventArgs e)
{
m_bIsActive = false;
}
private string RandomString(int size, bool lowerCase)
{
StringBuilder builder = new StringBuilder();
Random random = new Random();
char ch ;
for(int i=0; i<size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
builder.Append(ch);
}
if(lowerCase)
return builder.ToString().ToLower();
return builder.ToString();
}
}
}