Pravim C# Windows aplikacije, koje rade sa SQL Server CE bazom.
U pitanju su dve aplikacije koje rade nad istim SDF fajlom.
Prva aplikacija koristi SDF na svakih 5-6 minuta. Sve sto radi je da otvori konekciju, ocita podatke, i zatvori je. Sve radi najjednostavnije moguce:
Code:
SqlCeConnection con = new SqlCeConnection(connectReport);
SqlCeCommand cmd = new SqlCeCommand(sql, con);
SqlCeDataReader reader;
try
{
con.Open();
}
catch (SqlCeException sqlexception)
{
//Console.WriteLine(sqlexception.Message);
}
catch (Exception ex)
{
//Console.WriteLine(ex.Message);
}
int mySpeed = 0;
string tmpStrMy = "";
MyClass.contentImageList.Clear();
try
{
reader = cmd.ExecuteReader();
while (reader.Read())
{
MyClass.contentImageList.Add(reader[0]);
tmpStrMy = tmpStrMy + reader[0].ToString() + ",";
mySpeed = Convert.ToInt32(reader["My_Speed"]);
}
reader.Close();
}
catch (SqlCeException sqlexception)
{
//Console.WriteLine(sqlexception.Message);
}
catch (Exception ex)
{
//Console.WriteLine(ex.Message);
}
if (con.State == ConnectionState.Open)
{
try
{
con.Close();
}
catch (Exception ex) {
MessageBox.Show("Ne mogu da zatvorim konekciju - \n" + ex.ToString()); // ovo nikad ne javi
}
}
SqlCeConnection con = new SqlCeConnection(connectReport);
SqlCeCommand cmd = new SqlCeCommand(sql, con);
SqlCeDataReader reader;
try
{
con.Open();
}
catch (SqlCeException sqlexception)
{
//Console.WriteLine(sqlexception.Message);
}
catch (Exception ex)
{
//Console.WriteLine(ex.Message);
}
int mySpeed = 0;
string tmpStrMy = "";
MyClass.contentImageList.Clear();
try
{
reader = cmd.ExecuteReader();
while (reader.Read())
{
MyClass.contentImageList.Add(reader[0]);
tmpStrMy = tmpStrMy + reader[0].ToString() + ",";
mySpeed = Convert.ToInt32(reader["My_Speed"]);
}
reader.Close();
}
catch (SqlCeException sqlexception)
{
//Console.WriteLine(sqlexception.Message);
}
catch (Exception ex)
{
//Console.WriteLine(ex.Message);
}
if (con.State == ConnectionState.Open)
{
try
{
con.Close();
}
catch (Exception ex) {
MessageBox.Show("Ne mogu da zatvorim konekciju - \n" + ex.ToString()); // ovo nikad ne javi
}
}
Nad istim tim sdf fajlom, na vrlo slican nacin, radi jos jedna aplikacija. Pomocu
nje radim sa podacima koji se nalaze u SDF fajlu.
Problem koji mi se javlja je da se (skoro, ili u 90% slucajeva) svaki put kada
druga aplikacija pokusa da uradi najjednostavniji SELECT, vrati gresku:
Code:
There is a file sharing violation. A different process might be using the file.
There is a file sharing violation. A different process might be using the file.
Deluje kao da prva aplikacija (ona koja koristi SDF na svakih nekoliko minuta) ili
nije zatvorila konekciju (a jeste). Ili je nesto drugo u pitanju?
Da li mozete da mi pomognete i da mi kazete gde gresim, sta nisam uradio kako treba?