2011-10-04 25 views
0

我不確定如何標題問題。Sql參數似乎不會在字符串中添加單引號(commit transaction issue)

我有這塊代碼,它爲插入的存儲過程設置我的sql參數。

Dim sproc As StoredProcedure = New StoredProcedure("UsersInsert2", DataAccessConfiguration) 
    sproc.AddInput("@ID", SqlDbType.NVarChar, 10, entity.UserId) 
    sproc.AddInput("@PCode", SqlDbType.SmallInt, entity.PriviledgeCode) 
    sproc.AddInput("@Pwd", SqlDbType.NVarChar, 10, entity.Password.ToString()) 
    sproc.AddInput("@Lang", SqlDbType.NVarChar, 1, entity.DefaultLanguage) 
    sproc.AddInput("@Name", SqlDbType.NVarChar, 40, entity.UserName) 
    sproc.AddInput("@Notice", SqlDbType.TinyInt, entity.SaveNotice) 
    sproc.AddInput("@CreatedBy", SqlDbType.VarChar, 50,CurrentUserCredentials.UserName) 

我測試了存儲過程在SSMS中,它的工作原理。 問題是,當我嘗試從應用程序調用它。它失敗。 @@ rowcount = -1。我試着從數據庫返回一個錯誤代碼...沒有骰子。一直回來爲-1

什麼是會得到執行看起來像這樣

sproc = {EXEC UsersInsert2 @ID=ruxtest7, @PCode=0, @Pwd=1234, @Lang=E, @Name=ruxpint, @Notice=1, @CreatedBy=ruxpint} 

任何想法是什麼問題?我已經多次重複使用這段代碼。唯一的區別是我使用NVarChar,它是vb.net。

謝謝。

TR

+0

我希望爲SP和參數的不同數量的不同的名字都沒有問題... – gbianchi

+0

它調用了正確的存儲過程「UsersInsert2」。作爲測試,我更改了其中一個參數的名稱,但失敗了。我也從此刪除了大小。 (我把它放在初始搜索後) – TeddyRuxpin

+0

不要刪除大小。它會負面影響查詢計劃緩存。 – HardCode

回答

0

因此,事實證明我存儲的proc通話很好。在我執行事務的基類中,我忘了提交它。 D'哦! (這可以幫助別人,將來)

  Try 
       x = command.ExecuteNonQuery() 
       transaction.Commit() <- I was missing this line!!! 
      Catch ex As Exception 
       transaction.Rollback() 
      Finally 
       If conn.State And ConnectionState.Closed = 0 Then 
        conn.Close() 
       End If 
      End Try