ExecuteNonQuery: Connection property has not been initialized
-
28-06-2021 - |
Вопрос
I've seen this question asked here before, but never when Enterprise Library is used. I've used code like the following before and it works fine. What's the problem this time? I get the error on the last line:
Database db = new SqlDatabase(MyConfiguration.Current.ConnectionString);
DbCommand cmd = db.GetStoredProcCommand("AddWorkListItem");
db.AddInParameter(cmd, "@PartNumber", DbType.String, partNumber);
db.AddInParameter(cmd, "@Quantity", DbType.Int32, qty);
db.AddInParameter(cmd, "@WorkListTypeCode", DbType.String, code);
db.AddInParameter(cmd, "@UserKey", DbType.Int32, userKey);
return cmd.ExecuteNonQuery();
Решение
Gosh it's been a while but I'm pretty sure you call db.ExecuteNonQuery(cmd)
rather than cmd.ExecuteNonQuery()
. Have you tried that?
Не связан с StackOverflow