I've got a small personal project that I've been working on. I've suddenly got a weird error that's been plaguing me. The error is:
'Procedure or function 'RandomWordParts' expects parameter '@LangID', which was not supplied.'
The code (.net 6) calling the proc is:
public List<Syllable> RandomWordParts(int langID, int iter, int syllableCount)
{
List<Syllable> syllables = new();
SqlCommand cmd = new($"dbo.RandomWordParts", connection);
cmd.Parameters.AddWithValue("@LangID", langID);
cmd.Parameters.AddWithValue("@Iter", iter);
cmd.Parameters.AddWithValue("@SyllableCount", syllableCount);
connection.Open();
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
syllables.Add(new Syllable(reader));
connection.Close();
return syllables;
}
The stored proc params are:
ALTER proc [dbo].[RandomWordParts]
@LangID int,
@Iter int,
@SyllableCount int
as
...
It even works with a direct call, such as:
exec dbo.RandomWordParts
@LangID = 1,
@Iter = 0,
@SyllableCount = 2
What I have tried:
I've tried specifying the command type as StoredProc, but that doesn't work. I've tried renaming @LangID in both proc and code, and that didn't work. I've checked the Parameters collection and it's correct.
Currently doing this, which I hate:
public List<Syllable> RandomWordParts(int langID, int iter, int syllableCount)
{
List<Syllable> syllables = new();
SqlCommand cmd = new($"exec dbo.RandomWordParts {langID}, {iter}, {syllableCount} ", connection);
connection.Open();
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
syllables.Add(new Syllable(reader));
connection.Close();
return syllables;
}