•  914-288-5685
  •   sales@revindex.com
   Search
FR
0
 
  • Register
 
Login
Revindex
  • Products
    • -Comodo PCI Scan
    • -RapidSSL Certificate
    • -RapidSSL Wildcard Certificate
    • -Revindex Generic Skin
    • -Revindex Impersonator
    • -Revindex Omni Skin
    • -Revindex Optimizer
    • -Revindex Polo Skin
    • -Revindex Priority Support
    • -Revindex Storefront
    • -Revindex Storefront Service Plan
    • -Revindex Storefront Source
    • -Revindex Storefront Source Service Plan
    • -Revindex Task Scheduler
    • -Revindex Wiki
    • -Software License Modification
  • Services
    • -Design
    • -Programming
    • -Hosting
    • -Merchant Account
  • Resources
    • -Downloads
    • -Knowledge Base
      • --ASCII Characters
      • --HTML Entities
      • --Revindex Impersonator
      • --Revindex Optimizer
      • --Revindex Storefront
      • --Revindex Task Scheduler
      • --Revindex Wiki
      • --Standard DNN Tokens
    • -Tools
      • --Remote Ping
      • --Unit Converter
      • --URL Encoder Decoder
      • --HTML Encoder Decoder
      • --GUID Generator
    • -Blogs
  • Support
    • -Forum
    • -Frequently Asked Questions
    • -Support Ticket
  • Company
    • -About Us
    • -Customer Portfolio
    • -Customer Reviews
    • -Resellers
  • Free Trial
You are here: Resources ⁄ Knowledge Base ⁄ Revindex Task Scheduler

Revindex Task Scheduler

Email Export Print

Execute stored procedure (PowerShell)

This example shows how to execute a stored procedure from PowerShell.

# Assumption, the DBName connection string is in the web.config file
# Replace “DBName” with the actual database name

# Replace “120” with the actual Command Timeout required (in seconds)
# Replace “SPName” with the actual stored procedure name

# Replace “Parm1, Parm2” with the actual parameter name
# -----------------------------------------------------------------------
$ConnString = [DotNetNuke.Common.Utilities.Config]::GetConnectionString("DBName")
$SQLConnection = New-Object System.Data.SqlClient.SqlConnection
$SQLConnection.ConnectionString = $ConnString

$SQLCmdString = " DBName.dbo.SPName"
$SQLCmdTimeout = 120

$SQLCmd = New-Object System.Data.SqlClient.SqlCommand
$SQLCmd.CommandType = [System.Data.CommandType]::StoredProcedure
$SQLCmd.CommandText = $SQLCmdString
$SQLCmd.CommandTimeout = $SQLCmdTimeout
$SQLCmd.Connection = $SQLConnection


$SQLCmd.Parameters.Add("@Parm1",[system.data.SqlDbType]::Int) | out-Null
$SQLCmd.Parameters['@ Parm1'].Direction = [system.data.ParameterDirection]::Input
$SQLCmd.Parameters['@ Parm1'].value = 1


$SQLCmd.Parameters.Add("@Parm2",[system.data.SqlDbType]::Int) | out-Null
$SQLCmd.Parameters['@ Parm2'].Direction = [system.data.ParameterDirection]::Input
$SQLCmd.Parameters['@ Parm2'].value = 2


$SQLConnection.Open()
$SQLCmd.ExecuteNonQuery() | out-null
$SQLConnection.Close()

Comments

Add comment
Previous Next

Search

Search

Contents

  • Users manual
    • Overview
    • Installation
      • Requirements
      • How to install
      • How to upgrade
      • License key
      • Security
      • Timeout
      • Timer
    • Examples
      • Execute DOS commands (Program)
      • Execute program file (Program)
      • Get connection string (PowerShell)
      • Get connection string (Razor C#)
      • Execute stored procedure (PowerShell)
      • Execute stored procedure (Razor C#)
      • Load assemblies (PowerShell)
      • Load assemblies (Razor C#)
      • Send email (PowerShell)
      • Send email (Razor C#)
      • Using functions (Razor C#)
      • Web Get (PowerShell)
      • Web Get (Razor C#)
      • Web Post (PowerShell)
      • Web Post (Razor C#)
      • Write file (Razor C#)
      • Query database (SQL)
  • Release notes

Powered by Revindex Wiki

Copyright Revindex Inc. : Terms Of Use : Privacy Statement
Copyright Revindex Inc. : Terms Of Use : Privacy Statement