SQLite 데이터베이스를 C# WinForm으로 열고 예외 처리 및 이상한 오류가 발생했습니다. 이 코드를SQLite ADO.Net 및 오류 검사로 C# 형식을 초기화하는 중 오류가 발생했습니다.
bool TryingtoStart = true;
while (TryingtoSTart)
{
try
{
dbc.Open();
departmentDataAdapter = new SQLiteDataAdapter("select * from DEPARTMENT", dbc);
// etc
}
catch (SQLiteException ex)
{
DialogResult r = MetroFramework.MetroMessageBox.Show(this, ex.Message.ToString(), "Database error", MessageBoxButtons.RetryCancel);
if (r == DialogResult.Cancel) TryingtoStart = false;
}
catch (Exception exc)
{
DialogResult r = MetroFramework.MetroMessageBox.Show(this, exc.Message.ToString(), "Exception", MessageBoxButtons.RetryCancel);
if (r == DialogResult.Cancel) TryingtoStart = false;
}
if (!TryingtoStart) Application.Exit();
}
를 구현하고 오류를
"Operation is not valid due to the current state of the object."
실행을 얻을 수있다. 두 번째 catch() 즉 SQLException이 아닙니다. 내이나 저전압을 제거하면, 나는 및은 try/캐치, 모든 것이 잘 작동 while 루프를 제거하면
()를 호출 오픈의 행 번호와 오류를
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at System.Data.SQLite.SQLiteConnection.Open()
를 얻을. 이 코드는 Form_Load() 메서드에 있습니다.
나는 이것을 시도했지만 이해할 수 없다. 나는 몇 번 주석 처리하고 주석 처리를 해본 결과 오류가 일관되었다.
doh! Zohar에게 감사드립니다. if (dbc.State == ConnectionState.Open)와 같은 테스트가 중단됩니다. 잘 했어? 연결할 수있는 몇 가지 상태가 될 것으로 보인다 특히 열려 찾고 안전을 위해 –
내 대답에 코드를 확인하십시오. –