You are most likely inside of a transaction that is not committed. Perhaps the Dapper ORM has started a transaction and you must tell it to commit all changes.
To make it clear I've made a simple console app with only the only code above but there's still the same problem. – MaxFX May 4 at 8:14.
At a guess, the default for your server has been set such that implicit transactions have been turned on. What this means is that, if you execute a command and no transaction is currently open, SQL Server will automatically start a transaction (as always). But when the command completes successfully, this transaction is left open, and needs an explicit commit to be issued.To determine if this is the case, try querying @@OPTIONS: IF @@OPTIONS & 2 > 0 RAISERROR ('Implicit transactions are turned on', 1, 1).
This code in dapper should be: var name = "SomeName"; int t = c. Execute("INSERT INTO Users (UserName) VALUES (@name)", new {name}); Dapper does no internal transaction management, it must be passed in using the optional transaction param. My gut is telling me you are connecting to a different db to insert the data.
Either that of Damiens implicit transaction stuff, which is easy to validate.
– Developr Jul 18 at 9:35 1 c. Query("insert ... select SCOPE_IDENTITY()").First() .. not sure if numeric(38) maps cleanly to int @Developr – Sam Saffron? Jul 18 at 9:45 You are a rock star!
Thks – Developr Jul 18 at 10:59 My Identity column in SQL is int. No matter what I set the Dapper query to (int, long, etc), it is giving me a "Specified cast is not valid." exception on Dapper line: 1104 return (T)val; Is there not a way to do it with execute where I get it back as a output parameter similar to how the stored proc example works? Not sure that would be any cleaner, but would at least be a alternative.
– Developr Jul 18 at 11:45 BTW, the invalid cast was because it was treating the SQL returned int as a decimal! For now, I changed the c. Query and it is working, although it is a bit of a kludge.
– Developr Jul 18 at 11:53.
It may be the database is automatically creating a transaction that's not being committed, try creating your own transaction in the code and committing it manually and see if that works using (SqlConnection c = new SqlConnection(Settings.Default. UsersConnectionString)) { c.Open(); using (SqlTransaction t = c. BeginTransaction("InsertIntoUsers")) { using (SqlCommand d = new SqlCommand()) { d.
CommandText = "INSERT INTO Users (UserName) VALUES ('SomeName')"; d. CommandType = System.Data.CommandType. Text; d.
Connection = c; int t = d.ExecuteNonQuery(); } t.Commit(); } }.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.