Revindex Task Scheduler

Export Print

Get connection string (Razor C#)

You can get connection strings stored in your Web.config in Razor (C#) by issuing the following statement:


@using System.Data;
@using System.Data.SqlClient;
@{
  var connectionString = DotNetNuke.Common.Utilities.Config.GetConnectionString("SiteSqlServer")
  var connection = new SqlConnection(connectionString);
  var command = connection.CreateCommand();
  command.CommandText = "UPDATE table1 SET col1 = '1' WHERE col1 = '2'";
  connection.Open();
  command.ExecuteNonQuery();
  connection.Close();
}

Comments

Add comment

Powered by Revindex Wiki