私は複数の人で自分のAccessデータベースに接続しています。同時に2人の人が同時に検索している場合は、エラーが発生します。だから私はそれを修正するためにこれをやったが、それは多くのエラーを削減したが、私はまだ時々それを得る。より良い方法がありますか?私はかなりこのようなキャッチを使用してはならないと確信しています。このアクセスコードを修正するにはどうすればいいですか
public partial class Form2 : Form
{
private OleDbConnection connection = new OleDbConnection();
public Form2()
{
InitializeComponent();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=S:\Documents\2015\Db12.accdb";
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=S:\Documents\2015\Db12.accdb";
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST)
m.Result = (IntPtr)(HT_CAPTION);
}
private const int WM_NCHITTEST = 0x84;
private const int HT_CLIENT = 0x1;
private const int HT_CAPTION = 0x2;
private void lRead(string query, ListBox lbox)
{
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = query;
OleDbDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
lbox.Items.Add(reader["UAS"].ToString());
}
}
catch (Exception ex)
{ MessageBox.Show("error LREAD" + ex); }
finally
{
if (reader != null)
{ reader.Dispose(); }
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
try
{
connection.Open();
listBox1.Items.Clear();
lRead($"select * from Table1 where UAS Like '%{textBox1.Text}%'", listBox1);
lRead($"select * from Table1 where Customer Like '%{textBox1.Text}%'", listBox1);
lRead($"select * from Table1 where Description Like '%{textBox1.Text}%'", listBox1);
lRead($"select * from Table1 where Detail Like '%{textBox1.Text}%'", listBox1);
//select * from SomeTable Where SomeColumn Like '* PARMA *' dont use * use %
connection.Close();
}
catch
{
System.Threading.Thread.Sleep(500);
try
{
connection.Open();
listBox1.Items.Clear();
lRead($"select * from Table1 where UAS Like '%{textBox1.Text}%'", listBox1);
lRead($"select * from Table1 where Customer Like '%{textBox1.Text}%'", listBox1);
lRead($"select * from Table1 where Description Like '%{textBox1.Text}%'", listBox1);
lRead($"select * from Table1 where Detail Like '%{textBox1.Text}%'", listBox1);
//select * from SomeTable Where SomeColumn Like '* PARMA *' dont use * use %
connection.Close();
}
catch
{
System.Threading.Thread.Sleep(500);
try
{
connection.Open();
listBox1.Items.Clear();
lRead($"select * from Table1 where UAS Like '%{textBox1.Text}%'", listBox1);
lRead($"select * from Table1 where Customer Like '%{textBox1.Text}%'", listBox1);
lRead($"select * from Table1 where Description Like '%{textBox1.Text}%'", listBox1);
lRead($"select * from Table1 where Detail Like '%{textBox1.Text}%'", listBox1);
//select * from SomeTable Where SomeColumn Like '* PARMA *' dont use * use %
connection.Close();
}
catch
{
MessageBox.Show("Error too many People Searching ");
}
}
}
エラーと、それを引き起こしている行を教えてください。 – LarsTech
それはエラーではありません。デバッグする必要はありません。あまりにも多くの人がアクセスすると、私は接続をより良く処理する必要があります。 – AllianceMaterials
"エラーではありません。"確かに問題が発生したときに何かが起こり、それを共有することができます。 – Brad