I have a few functions that use the SqlCommand object to to data inserts, and queries. But one function (the last one in the file) seems to echo (most of) the attributes into the output. The function in question:
function Add-DataStudentChangeEvent($person,
$key,
$currentValue,
$newValue,
$eventType){
$cmdEvent=New-Object System.Data.SqlClient.SqlCommand
$cmdEvent.Connection = $conn
$cmdEvent.CommandTimeout = 600000
$cmdEvent.CommandText = "INSERT INTO ChangeEvent
(AttributeKey
,CurrentAttributeValue
,NewAttributeValue
,EventType
,EventDate
,CompletedStatus
,Person_Id)
VALUES
(@AttributeKey,
@CurrentAttributeValue,
@NewAttributeValue,
@EventType,
GETDATE(),
0,
@PersonId);" -F
$cmdEvent.Parameters.AddWithValue("@AttributeKey", $key);
$cmdEvent.Parameters.AddWithValue("@CurrentAttributeValue", $current);
$cmdEvent.Parameters.AddWithValue("@NewAttributeValue", $updateTo);
$cmdEvent.Parameters.AddWithValue("@EventType", $eventType);
$cmdEvent.Parameters.AddWithValue("@PersonId", $person);
$cmdEvent.ExecuteNonQuery()
}
In another similar function using parameterized queries I found that adding the -F
at the end, stops the echo. And I did say most of the parameters. Only 4 of the 5 actually display. This is the output I'm getting:
1
CompareInfo : None
XmlSchemaCollectionDatabase :
XmlSchemaCollectionOwningSchema :
XmlSchemaCollectionName :
ForceColumnEncryption : False
DbType : String
LocaleId : 0
ParameterName : @CurrentAttributeValue
Precision : 0
Scale : 0
SqlDbType : NVarChar
SqlValue : Null
UdtTypeName :
TypeName :
Value :
Direction : Input
IsNullable : False
Offset : 0
Size : 0
SourceColumn :
SourceColumnNullMapping : False
SourceVersion : Current
CompareInfo : None
XmlSchemaCollectionDatabase :
XmlSchemaCollectionOwningSchema :
XmlSchemaCollectionName :
ForceColumnEncryption : False
DbType : String
LocaleId : 0
ParameterName : @NewAttributeValue
Precision : 0
Scale : 0
SqlDbType : NVarChar
SqlValue : 2007-11-15
UdtTypeName :
TypeName :
Value : 2007-11-15
Direction : Input
IsNullable : False
Offset : 0
Size : 10
SourceColumn :
SourceColumnNullMapping : False
SourceVersion : Current
CompareInfo : None
XmlSchemaCollectionDatabase :
XmlSchemaCollectionOwningSchema :
XmlSchemaCollectionName :
ForceColumnEncryption : False
DbType : Int32
LocaleId : 0
ParameterName : @EventType
Precision : 0
Scale : 0
SqlDbType : Int
SqlValue : 1
UdtTypeName :
TypeName :
Value : 1
Direction : Input
IsNullable : False
Offset : 0
Size : 0
SourceColumn :
SourceColumnNullMapping : False
SourceVersion : Current
CompareInfo : None
XmlSchemaCollectionDatabase :
XmlSchemaCollectionOwningSchema :
XmlSchemaCollectionName :
ForceColumnEncryption : False
DbType : Int32
LocaleId : 0
ParameterName : @PersonId
Precision : 0
Scale : 0
SqlDbType : Int
SqlValue : 72
UdtTypeName :
TypeName :
Value : 72
Direction : Input
IsNullable : False
Offset : 0
Size : 0
SourceColumn :
SourceColumnNullMapping : False
SourceVersion : Current
Any ideas on how I can stop the echo?