Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Professional Windows PowerShell Programming ISBN: 978-0-470-17393-0
This is the forum to discuss the Wrox book Professional Windows PowerShell Programming: Snapins, Cmdlets, Hosts and Providers by Arul Kumaravel, Jon White, Michael Naixin Li, Scott Happell, Guohui Xie, Krishna C. Vutukuri; ISBN: 9780470173930
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Windows PowerShell Programming ISBN: 978-0-470-17393-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 25th, 2011, 12:39 PM
Registered User
 
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trying to execute a SQL stored procedure and it fails

I have written and tested a stored procedure in my ms sql database I am now trying to pass multiple parameters and run it. This one is just a simple insert procedure. I debug the powershell script and it opens the connection with the server but fails to pass the parameters. with the below error.

Exception calling "ExecuteNonQuery" with "0" argument(s): "Procedure or function 'sp_insertmds3re' expects parameter '@subid', which was not supplied

I do supply that paramter. here is the script below.

$sqlserver= "server"
$sqldatabase = "db"
$UserName="login"
$Password="password"
$dbDefine="Server=$sqlserver;Database=$sqldatabase ;Uid=$UserName;Password=$Password;"
$DBConnection=New-Object System.Data.SqlClient.SqlConnection
$DBCommand=New-Object System.Data.SqlClient.SqlCommand
$DBCommand.Connection = $DBConnection
$DBCommand.commandtext = "[sp_insertmds3re]"
$DBCommand.CommandType = [System.Data.CommandType]::StoredProcedure

$DBCommand.Parameters.Add("`'1`'",[system.Data.SqlDbType]::Int) | Out-Null
$DBCommand.Parameters.Add("`'5/1/2010 12:00:00 AM`'",[System.Data.SqlDbType]::SmallDateTime) |Out-Null
$DBCommand.Parameters.Add("`'Name`'",[system.Data.SqlDbType]::VarChar,20)| Out-Null
$DBCommand.Parameters.Add("`'1`'",[system.Data.SqlDbType]::SmallInt) | Out-Null
$DBCommand.Parameters.Add("`'2`'",[system.Data.SqlDbType]::SmallInt)| Out-Null
$DBCommand.Parameters.Add("`'3`'",[system.Data.SqlDbType]::SmallInt)| Out-Null
$DBCommand.Parameters.Add("`'Completed`'",[system.Data.SqlDbType]::VarChar,20)| Out-Null
$DBConnection.ConnectionString=$dbDefine
$DBConnection.Open()

$DBCommand.ExecuteNonQuery()

$DBConnection.Close()




Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't See SQL tables and Stored Procedure azambee SQL Server 2000 1 October 24th, 2008 01:03 PM
Execute Stored Procedure from VBA Romashka Access VBA 1 February 22nd, 2007 12:52 PM
SQL Server Stored Procedure doug SQL Server 2000 2 February 22nd, 2005 03:04 PM
dymanic sql vs stored procedure prox_lae Oracle 0 February 19th, 2004 10:30 PM
SQL Stored Procedure... babloo81 SQL Server ASP 1 December 8th, 2003 03:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.