public Stream GetStream(int id, string filename) { Trace.WriteLine("DBImagePlugin - GetStream"); var connectionObj = GetConnectionObj(); connectionObj.Open(); Stream stream; using (connectionObj) { var sqlDataReader = new SqlCommand(imageBlobQuery, connectionObj) { Parameters = { CreateParameter("id", id, SqlDbType.Int), CreateParameter("name", filename, SqlDbType.NVarChar) } }.ExecuteReader(); using (sqlDataReader) { if (!sqlDataReader.Read()) { throw new FileNotFoundException("Failed to find the specified image " + id + " in the database"); } stream = sqlDataReader.GetSqlBytes(0).Stream; } } return stream; }
private void button11_Click(object sender, EventArgs e) { try { string netFileName = VissimSingleton.Instance.GetInputFileName(); string workingDir = VissimSingleton.Instance.GetWorkingDirectory(); string exeDir = VissimSingleton.Instance.GetExecutionDirectory(); if (workingDir == exeDir) throw new Exception("ex"); var files = Directory.GetFiles(workingDir, "*.*", SearchOption.TopDirectoryOnly); foreach (string fileName in files) { File.Delete(fileName); } var sb = new SqlConnectionStringBuilder(); sb.DataSource = "TOSHIBA"; sb.InitialCatalog = "VISSIM"; sb.IntegratedSecurity = true; using (var conn = new SqlConnection(sb.ConnectionString)) { conn.Open(); using (var reader = new SqlCommand("SELECT * FROM Files;", conn).ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { using (var fs = new FileStream(workingDir + reader.GetString(1), FileMode.Create, FileAccess.Write)) { var bytes = reader.GetSqlBytes(3); fs.Write(bytes.Buffer, 0, (int)bytes.Length); } } } } } VissimSingleton.Instance.LoadNet(workingDir + netFileName); VissimSingleton.Instance.LoadLayout(workingDir + "vissim.ini"); } catch (Exception ex) { MessageBox.Show(this, ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } }