Can't figure out where I'm going wrong here, the TVP in the stored procedure references @asn
but I keep getting the below error/warning, I've tried everything, there is no further details in the sql server logs, any help appreciated.
PowerShell function:
Function Execute-Procedure {
Param(
[Parameter(Mandatory=$true)][array]$p
)
Process {
$connectionString = "Server=;Database=;User ID=;Password=;Trusted_Connection=True"
$conn = New-Object System.Data.SqlClient.SqlConnection $connectionString
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.Connection = $conn
$cmd.CommandTimeout = 0
$pvar = ("V-" + $p.ToString())
$sqlParam = New-Object System.Data.SqlClient.SqlParameter("@asn", $pvar)
$null = $cmd.Parameters.Add($sqlParam, [System.Data.SqlDbType]::NVarChar)
$cmd.CommandText = "EXEC tsp_insert_asn @asn"
try {
$conn.Open()
$cmd.ExecuteNonQuery() | Out-Null
} catch [Exception] {
Write-Warning $_.Exception.Message
} finally {
$conn.Dispose()
$cmd.Dispose()
}
}
}
Stored procedure:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[tsp_insert_asn]
@asn AS [dbo].[tvp_asn] READONLY
AS
BEGIN
INSERT INTO [dbo].[asn]
SELECT asn_id
, name
, size
, location
,GETDATE()
FROM @asn;
END
Error:
WARNING: The parameterized query '(@asn nvarchar(4000))EXEC tsp_insert_asn @asn' expects the parameter '@asn', which was not supplied.