Hi nedash,
Refer below code.
C#
protected void Restore(object sender, EventArgs e)
{
string data = System.IO.File.ReadAllText(Server.MapPath("~/Test.sql"));
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
SqlCommand cmd = new SqlCommand(data, con);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
VB.Net
Protected Sub Restore(ByVal sender As Object, ByVal e As EventArgs)
Dim data As String = System.IO.File.ReadAllText(Server.MapPath("~/Test.sql"))
Dim con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
Dim cmd As SqlCommand = New SqlCommand(data, con)
cmd.CommandType = CommandType.Text
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub