Thursday, July 7, 2011

Can you Die from a Camera Flash?

Hi Friends,

Today I received a mail delivering me a shocking news of a boy's death due to camera's flashlight. At first I thought it was a hoax but after certain research over the internet this seems quite possible. This was the mail which I received:

Can current travel through Flash light of camera to your body? yes it is 100% true
 Yesterday morning, one Mr. Aditya Suresh Joshi, age 19, studying in 1st year of engineering, died in Keshvani Hospital, Mumbai. He was admitted in Keshavani Hospital as burned patient.Reason4 days back this boy had gone to Amravati (One of the district place located in State of Maharashtra ) on study tour. After their study was over, he, his classmates & his teachers, all of them were standing on "Badnera" railway station to catch the train. "Badnera" is the name of the railway station for" Amravati " city. As soon as they arrived on Badnera Railway station, many of them started taking pictures of their friends using "Mobile Phones" and/or "Digital Camera". One of them complained that, in his camera, he was not able to capture more number of friends in one frame. He was not able to catch the angle. Another boy suggested that let's climb on train boogie and take picture so that all of them can be accommodated in single frame.At that there was one goods wagon (all of them were oil tankers) train resting between 2 main railway lines. Kumar Aditya climbed up oil boogie. Above his head, 40,000 volts electrical line was passing through. As soon as he clicked the digital camera? 40,000 volt current passed through the camera flash light to his camera and then from his camera to his fingers and then from his fingers to his body. All this happened within fraction of minutes. Next moment he was thrown from the top. His body was half burned on the spot.At that time, his father was traveling in Bangkok . His many friends in Pune came to know about this via mobile SMS. They instantly arranged air ambulance in Amravati and his burned body was brought to Keshavani Hospital , Mumbai. For 1 and 1/2 day or so he was talking to his relatives. When he was admitted to the hospital, at that time only, doctor informed his relatives that don't keep great hopes. Because of lot of complex issues in half burned body. He died yesterday morning.Now how many of us are aware about this technological threats & dangers? Honestly, Kumar Aditya and his father were not aware. His family was not aware. There entire friend circle of more than 12,000, were not aware. Now should we call ourselves as fully educated and fully knowledgeable people? Please Think of it.Please avoid mobile phones on petrol outlets.Please avoid talking on mobile phones while driving. Many do not bother about this good suggestion and opt for "Chalta Hai Attitude".Please avoid talking on mobile phones while they are in charging mode.Please avoid charging mobile phones near Your bed and/or near wooden furniture. Avoid mobile phones near high voltage electrical lines like railway stations and use flash lights.We all learned our lesson with loss of young life. Now Would You like to empower Your friends about this accident so as to avoid future accidents? We can save human life by empowering all the IT users who are in Your network?What can we do ?Please request you to send this very important life threateninginformation to your loved ones.....

I did search over and found out that electronic flash, as used on and in cameras, needs a high-voltage discharge across the flash-tube to initiate the intense burst of light. This is achieved by charging up a 'reservoir' capacitor to store the power needed for the flash until it is required. When the flash activates the capacitor discharges, initiating the high-voltage discharge but this action also generates an intense electromagnetic field. It can be this field which smoothened the flow between the power-line and the camera.

The quote from a forum site explains an earlier experience of getting shock from a battery-less camera during operation. The vital experience provided by the quote says:
When i was around 15, i got a strong electrical shock while repairing my camera.(even when it had no batteries or other connection!) later i found out that it was because the cameras use high potential to generate flash light, and for this they use a high value capacitor, (and i don't think i want to give the definition of capacitor.), and as i conclude, the current which passed through the digital camera of that unfortunate boy was because of the discharging of the capacitor while flashing and attracting the high amperes passing above. THE FLASH DID NOT ATRACTED THE CURRENT, it was because of the LC (inductor-capacitor) circuit and field generation.
PROOF: I am an Electronics and Telecommunication Engineering student in 3rd year, and I’ve consulted my HOD about this topic. (I’ll give you his number if you ask!!) 
That said, many would still not believe the fact untill googling or until Einstein/Faraday states it after a re-birth :P You can discuss on this topic to get numerous other views, but the bottom-line remains the same: Take Care :)

Monday, July 4, 2011

Optimized Insert Process for a database in asp.net c#

There are many ways to insert data into a database. Particularly in asp.net and c#, we use SQLClient class to include database related functionalities in our programming part. He are the three ways i generally use, presented before you to check the process:

Using Data Adapter with Dataset:

DataRow dr = dsTab.Tables["Table1"].NewRow();
DataSet dsTab = new DataSet("Table1");
SqlDataAdapter adp = new SqlDataAdapter("Select * from Table1", connection);
adp.Fill(dsTab, "Table1");
dr["col1"] = txtBox1.Text;
dr["col2"] = txtBox5.Text;    
dr["col3"] = "text";

dsTab.Tables["Table1"].Rows.Add(dr);
SqlCommandBuilder projectBuilder = new SqlCommandBuilder(adp);
DataSet newSet = dsTab.GetChanges(DataRowState.Added);
adp.Update(newSet, "Table1");

Data Adapter using Command:

SqlDataAdapter AdapterMessage = new SqlDataAdapter();
AdapterMessage.InsertCommand = new SqlCommand();
AdapterMessage.InsertCommand.Connection = con;
AdapterMessage.InsertCommand.CommandText = "insert into Table1(col1,col2,col3) values ('" + txtBox1.Text + "','" + txtBox2.Text + "','" + User.Identity.Name.ToString(); + "')";
AdapterMessage.InsertCommand.ExecuteNonQuery();
AdapterMessage.Dispose();

SQL Command

string query = "insert into Table1(col1,col2,col3) values (@value1,@value2,@value3)";
int i;
SqlCommand cmd = new SqlCommand(query, connection);
// add parameters...
cmd.Parameters.Add("@value1",SqlDbType.VarChar).Value=txtBox1.Text;
cmd.Parameters.Add("@value2",SqlDbType.VarChar).Value=txtBox2.Text;
cmd.Parameters.Add("@value3",SqlDbType.VarChar).Value=txtBox3.Text;
cmd.con.open();
i = cmd.ExecuteNonQuery();
cmd.con.close();


These are the one among many methods to use while inserting a new row into the database table. The first example uses data adapter and data set, calling the update method of adapter to perform the insert. The second method method uses the sql command object of data adapter to perform the insert operation. The third operation uses   the SQL command object only, for performing the insert operation.

This should be noted that the second method is highly prone to SQL injection attacks :X The website is thus prone to hacking if the query is written as described in the second method. The simple way to avoid SQL injection attacks is to use parameters in the query as done in the third case.

Now it may seem that the third case will have the faster performance time but it should also be noted that even data adapter also uses the same executeNonQuery methods and the connection opening/closing by itself. As the underlying functions are same, there isn't much difference in performance. Now what's an eye candy is that, updating a data source is much easier using DataAdapters. It's easier to make changes since we only need to modify the dataset and call an Update.

The SQL command is still handy when we have perform a simple single insert operation. That said, it now depends upon you to choose which suits you during your development. However what if there are bulk of data to be inserted into the database? :X :P

Well relax!!! There is a special SqlBulkCopy class residing in System.Data.SqlClient.SqlBulkCopy namespace which aids us in bulk insert situation. A sample example of using the same can be:

DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(); SqlBulkCopy sbc = new SqlBulkCopy(con);
sbc.DestinationTableName = "dbo.SomeTable";
sbc.WriteToServer(dt);
sbc.Close();

But its should be kept in mind that the schema of the database table must be same as that of the table in which the insert operation is performed. Hope it helped some of you :)