Error could not find stored procedure with Dapper and c# only when I specify commandType











up vote
1
down vote

favorite












I'm using Dapper with C# and SQL Server. I have an stored procedure in SQL Server that inserts a person into my database. The problem is that when I specify in the query that its an stored procedure I get




Could not find stored procedure




but without using commandType, everything works fine.



For example: I had the following code:



var result = connection.Execute("KBunnyGame_Players_InsertPlayer @Name, @Score, @FacebookId", player, commandType: CommandType.StoredProcedure);


And I kept getting the error, but after I changed to:



var result = connection.Execute("KBunnyGame_Players_InsertPlayer @Name, @Score, @FacebookId", player);


I didn't get the error anymore and the player got inserted in the database.
I don't know if that's the expected behaviour, it seems weird to me. Is there any documentation I could follow?



EDIT:



Stored procedure code:



ALTER PROCEDURE [dbo].[KBunnyGame_Players_InsertPlayer] 
@Name NCHAR(20),
@Score INT,
@FacebookId NCHAR(50)
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO KBunnyGame_Players (name, score, facebookId)
VALUES (@Name, @Score, @FacebookId);
END









share|improve this question
























  • @mjwills Thanks for the suggestion, already done
    – Teler
    yesterday










  • Does stackoverflow.com/a/25592031 help?
    – mjwills
    yesterday















up vote
1
down vote

favorite












I'm using Dapper with C# and SQL Server. I have an stored procedure in SQL Server that inserts a person into my database. The problem is that when I specify in the query that its an stored procedure I get




Could not find stored procedure




but without using commandType, everything works fine.



For example: I had the following code:



var result = connection.Execute("KBunnyGame_Players_InsertPlayer @Name, @Score, @FacebookId", player, commandType: CommandType.StoredProcedure);


And I kept getting the error, but after I changed to:



var result = connection.Execute("KBunnyGame_Players_InsertPlayer @Name, @Score, @FacebookId", player);


I didn't get the error anymore and the player got inserted in the database.
I don't know if that's the expected behaviour, it seems weird to me. Is there any documentation I could follow?



EDIT:



Stored procedure code:



ALTER PROCEDURE [dbo].[KBunnyGame_Players_InsertPlayer] 
@Name NCHAR(20),
@Score INT,
@FacebookId NCHAR(50)
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO KBunnyGame_Players (name, score, facebookId)
VALUES (@Name, @Score, @FacebookId);
END









share|improve this question
























  • @mjwills Thanks for the suggestion, already done
    – Teler
    yesterday










  • Does stackoverflow.com/a/25592031 help?
    – mjwills
    yesterday













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm using Dapper with C# and SQL Server. I have an stored procedure in SQL Server that inserts a person into my database. The problem is that when I specify in the query that its an stored procedure I get




Could not find stored procedure




but without using commandType, everything works fine.



For example: I had the following code:



var result = connection.Execute("KBunnyGame_Players_InsertPlayer @Name, @Score, @FacebookId", player, commandType: CommandType.StoredProcedure);


And I kept getting the error, but after I changed to:



var result = connection.Execute("KBunnyGame_Players_InsertPlayer @Name, @Score, @FacebookId", player);


I didn't get the error anymore and the player got inserted in the database.
I don't know if that's the expected behaviour, it seems weird to me. Is there any documentation I could follow?



EDIT:



Stored procedure code:



ALTER PROCEDURE [dbo].[KBunnyGame_Players_InsertPlayer] 
@Name NCHAR(20),
@Score INT,
@FacebookId NCHAR(50)
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO KBunnyGame_Players (name, score, facebookId)
VALUES (@Name, @Score, @FacebookId);
END









share|improve this question















I'm using Dapper with C# and SQL Server. I have an stored procedure in SQL Server that inserts a person into my database. The problem is that when I specify in the query that its an stored procedure I get




Could not find stored procedure




but without using commandType, everything works fine.



For example: I had the following code:



var result = connection.Execute("KBunnyGame_Players_InsertPlayer @Name, @Score, @FacebookId", player, commandType: CommandType.StoredProcedure);


And I kept getting the error, but after I changed to:



var result = connection.Execute("KBunnyGame_Players_InsertPlayer @Name, @Score, @FacebookId", player);


I didn't get the error anymore and the player got inserted in the database.
I don't know if that's the expected behaviour, it seems weird to me. Is there any documentation I could follow?



EDIT:



Stored procedure code:



ALTER PROCEDURE [dbo].[KBunnyGame_Players_InsertPlayer] 
@Name NCHAR(20),
@Score INT,
@FacebookId NCHAR(50)
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO KBunnyGame_Players (name, score, facebookId)
VALUES (@Name, @Score, @FacebookId);
END






c# dapper






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 16 hours ago









marc_s

564k12510871240




564k12510871240










asked yesterday









Teler

9919




9919












  • @mjwills Thanks for the suggestion, already done
    – Teler
    yesterday










  • Does stackoverflow.com/a/25592031 help?
    – mjwills
    yesterday


















  • @mjwills Thanks for the suggestion, already done
    – Teler
    yesterday










  • Does stackoverflow.com/a/25592031 help?
    – mjwills
    yesterday
















@mjwills Thanks for the suggestion, already done
– Teler
yesterday




@mjwills Thanks for the suggestion, already done
– Teler
yesterday












Does stackoverflow.com/a/25592031 help?
– mjwills
yesterday




Does stackoverflow.com/a/25592031 help?
– mjwills
yesterday












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










Don't specify the parameters in the command-text when using CommandType.StoredProcedure; provide just the name - the parameters are passed by name already.



If you need to filter the properties on the object, use a projection:



var result = connection.Execute("KBunnyGame_Players_InsertPlayer",
new { player.Name, player.Score, player.FacebookId },
commandType: CommandType.StoredProcedure);


SQL Server has implicit EXEC if something looks sufficiently close enough to an EXEC, which is why the other version works. So if you prefer: use that. With or without a leading EXEC.






share|improve this answer





















  • It works, thanks a lot. Just a small question, is there any difference between specifying the commandType.StoredProcedure, and using it without it?, or is it the same either way?
    – Teler
    yesterday










  • @Teler ADO.NET (and more specifically: SqlClient) treats the two scenarios very differently. With just the name and with CommandType.Text (or omitted) you wouldn't actually be passing the parameters - you'd be invoking it with the default parameters
    – Marc Gravell
    yesterday













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234319%2ferror-could-not-find-stored-procedure-with-dapper-and-c-sharp-only-when-i-specif%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










Don't specify the parameters in the command-text when using CommandType.StoredProcedure; provide just the name - the parameters are passed by name already.



If you need to filter the properties on the object, use a projection:



var result = connection.Execute("KBunnyGame_Players_InsertPlayer",
new { player.Name, player.Score, player.FacebookId },
commandType: CommandType.StoredProcedure);


SQL Server has implicit EXEC if something looks sufficiently close enough to an EXEC, which is why the other version works. So if you prefer: use that. With or without a leading EXEC.






share|improve this answer





















  • It works, thanks a lot. Just a small question, is there any difference between specifying the commandType.StoredProcedure, and using it without it?, or is it the same either way?
    – Teler
    yesterday










  • @Teler ADO.NET (and more specifically: SqlClient) treats the two scenarios very differently. With just the name and with CommandType.Text (or omitted) you wouldn't actually be passing the parameters - you'd be invoking it with the default parameters
    – Marc Gravell
    yesterday

















up vote
2
down vote



accepted










Don't specify the parameters in the command-text when using CommandType.StoredProcedure; provide just the name - the parameters are passed by name already.



If you need to filter the properties on the object, use a projection:



var result = connection.Execute("KBunnyGame_Players_InsertPlayer",
new { player.Name, player.Score, player.FacebookId },
commandType: CommandType.StoredProcedure);


SQL Server has implicit EXEC if something looks sufficiently close enough to an EXEC, which is why the other version works. So if you prefer: use that. With or without a leading EXEC.






share|improve this answer





















  • It works, thanks a lot. Just a small question, is there any difference between specifying the commandType.StoredProcedure, and using it without it?, or is it the same either way?
    – Teler
    yesterday










  • @Teler ADO.NET (and more specifically: SqlClient) treats the two scenarios very differently. With just the name and with CommandType.Text (or omitted) you wouldn't actually be passing the parameters - you'd be invoking it with the default parameters
    – Marc Gravell
    yesterday















up vote
2
down vote



accepted







up vote
2
down vote



accepted






Don't specify the parameters in the command-text when using CommandType.StoredProcedure; provide just the name - the parameters are passed by name already.



If you need to filter the properties on the object, use a projection:



var result = connection.Execute("KBunnyGame_Players_InsertPlayer",
new { player.Name, player.Score, player.FacebookId },
commandType: CommandType.StoredProcedure);


SQL Server has implicit EXEC if something looks sufficiently close enough to an EXEC, which is why the other version works. So if you prefer: use that. With or without a leading EXEC.






share|improve this answer












Don't specify the parameters in the command-text when using CommandType.StoredProcedure; provide just the name - the parameters are passed by name already.



If you need to filter the properties on the object, use a projection:



var result = connection.Execute("KBunnyGame_Players_InsertPlayer",
new { player.Name, player.Score, player.FacebookId },
commandType: CommandType.StoredProcedure);


SQL Server has implicit EXEC if something looks sufficiently close enough to an EXEC, which is why the other version works. So if you prefer: use that. With or without a leading EXEC.







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Marc Gravell

767k19021122526




767k19021122526












  • It works, thanks a lot. Just a small question, is there any difference between specifying the commandType.StoredProcedure, and using it without it?, or is it the same either way?
    – Teler
    yesterday










  • @Teler ADO.NET (and more specifically: SqlClient) treats the two scenarios very differently. With just the name and with CommandType.Text (or omitted) you wouldn't actually be passing the parameters - you'd be invoking it with the default parameters
    – Marc Gravell
    yesterday




















  • It works, thanks a lot. Just a small question, is there any difference between specifying the commandType.StoredProcedure, and using it without it?, or is it the same either way?
    – Teler
    yesterday










  • @Teler ADO.NET (and more specifically: SqlClient) treats the two scenarios very differently. With just the name and with CommandType.Text (or omitted) you wouldn't actually be passing the parameters - you'd be invoking it with the default parameters
    – Marc Gravell
    yesterday


















It works, thanks a lot. Just a small question, is there any difference between specifying the commandType.StoredProcedure, and using it without it?, or is it the same either way?
– Teler
yesterday




It works, thanks a lot. Just a small question, is there any difference between specifying the commandType.StoredProcedure, and using it without it?, or is it the same either way?
– Teler
yesterday












@Teler ADO.NET (and more specifically: SqlClient) treats the two scenarios very differently. With just the name and with CommandType.Text (or omitted) you wouldn't actually be passing the parameters - you'd be invoking it with the default parameters
– Marc Gravell
yesterday






@Teler ADO.NET (and more specifically: SqlClient) treats the two scenarios very differently. With just the name and with CommandType.Text (or omitted) you wouldn't actually be passing the parameters - you'd be invoking it with the default parameters
– Marc Gravell
yesterday




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234319%2ferror-could-not-find-stored-procedure-with-dapper-and-c-sharp-only-when-i-specif%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation