Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > BOOK: Professional Windows PowerShell Programming ISBN: 978-0-470-17393-0
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 25th, 2011, 11:39 AM
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()
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 11:52 AM
SQL Server Stored Procedure doug SQL Server 2000 2 February 22nd, 2005 02:04 PM
dymanic sql vs stored procedure prox_lae Oracle 0 February 19th, 2004 09:30 PM
SQL Stored Procedure... babloo81 SQL Server ASP 1 December 8th, 2003 02:38 PM



All times are GMT -4. The time now is 11:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.