I have saved my database files in App_Data directory and I used following code for connection to database files
Code:
SqlConnection con;
con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFileName=C://onlineexam.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
con.Open();