내 Access 데이터베이스에 여러 사람이 연결되어 있고 두 사람이 동시에 검색하는 경우 오류가 발생합니다. 그래서 그것을 고치기 위해 이것을했는데 오류를 많이 줄였습니다. 그러나 나는 때때로 그것을 때때로 얻습니다. 더 좋은 방법이 있습니까? 나는 이런 식으로 잡으려고해서는 안된다고 확신한다.이 액세스 코드를 수정하는 방법
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 ");
}
}
}
Google에 오류와 어떤 원인이 있는지 알려줘야합니다. – LarsTech
그것은 디버깅이 필요 없다는 오류가 아닙니다. 너무 많은 사람들이 액세스 할 때 오류가 있습니다. 내 시도를 통해 연결을 처리해야합니다. – AllianceMaterials
"오류가 아닙니다" "오류가 발생했습니다." 확실히 문제가 발생하면 문제가 발생합니다. – Brad