So i was trying to create multiple SQLite file base on the number of my network. It has successfully created the SQLite files but when i tried to make it a zip file it gave me an exception that cannot access the file because it is being used by another process.
SqlConnection conn = new SqlConnection(cmn.connString);
conn.Open();
string query = "select networkid, network from custom_networkList";
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
int networkid = Convert.ToInt32(reader["networkid"]);
string network = reader["network"].ToString();
File.Copy(Templatefile, newfile + network + ".sqlite", true);
SQLiteConnection m_dbConnection = new SQLiteConnection(@"Data Source=" + newfile + network + ".sqlite;Version=3;");
m_dbConnection.Open();
SQLiteCommand command = new SQLiteCommand("begin", m_dbConnection);
command.ExecuteNonQuery();
insertZone(m_dbConnection);
InsertJunctions(m_dbConnection, networkid);
InsertHydrant(m_dbConnection, networkid);
insertWaterTank(m_dbConnection, networkid);
insertPump(m_dbConnection, networkid);
InsertReservoir(m_dbConnection, networkid);
insertValve(m_dbConnection, networkid);
insertPipe(m_dbConnection, networkid);
command = new SQLiteCommand("end", m_dbConnection);
command.ExecuteNonQuery();
m_dbConnection.Close();
command.Dispose();
m_dbConnection.Dispose();
}
conn.Close();
GC.WaitForPendingFinalizers();
GC.Collect();
if (!Directory.Exists(newfilename))
{
// Try to create the directory.
File.Delete(newfilename);
}
ZipFile.CreateFromDirectory(newfile, newfilename, CompressionLevel.Fastest, true);
Directory.Delete(newfile,true);
return newfilename2;