Search

Index

Revindex Task Scheduler

Get connection string (Razor C#)

Last updated on 2015-03-25 1 mins. to read

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


Powered by Revindex Wiki