I have a database with a role sa.
When I execute the stored procedure which inserts a record to the table. However, when I run the same stored procedure via the ADO.NET code, the record is not getting inserted successfully. However, I can see that that the stored procedure has been called and runs successfully up to ExecuteQuery
.
Tried adding a transaction and commit and still no luck.
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
conn.Open();
using (SqlCommand command = conn.CreateCommand())
{
command.CommandText = "InsertData";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@Id", Id);
command.Parameters.AddWithValue("@name", Name);
command.ExecuteNonQuery();
}
}
Stored procedure:
CREATE PROCEDURE [dbo].[InsertData]
@Id INT,
@name VARCHAR(50)
AS
SET NOCOUNT ON;
INSERT INTO Employee (Id, Name)
VALUES (@Id, @name)
GO
var ConnectionString = "Data Source=xxxx;Initial Catalog=xxxx;Persist Security Info=True;User Id=xxxx;Password=xxxxx;MultipleActiveResultSets=True";