Galahtech

Development => Web Development => Topic started by: simmo on December 07, 2012, 05:56:43 pm



Title: ASP.Net (VB) - stored procedure not firing? **Resolved**
Post by: simmo on December 07, 2012, 05:56:43 pm
Ok, I've a bit of code that runs and feeds data from an xml file into a database table. In the process of doing that, I run a stored proc that will delete old data fed in on previous runs... but the data is not being deleted...

I know it is not the sproc itself, because I can run that via the query analyzer and records are deleted.

I know the code (posted below) is firing because I get "success" in my gErrorMsg that I am setting.

Is there something stupid I am not seeing, like I'm not executing the sproc, or something?  :crash:


Code:
   Private Function dropLSItems(ByVal fSellerId As Integer) As Boolean
        Dim sqlConn2 As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("constring").ToString())
        Dim cmd2 As SqlCommand = sqlConn2.CreateCommand
        cmd2.CommandType = CommandType.StoredProcedure

        cmd2.CommandText = "uspDeleteLsItems_BySellerId"
        cmd2.Parameters.AddWithValue("@SellerId", fSellerId)

        Using (sqlConn2)
            Try
                sqlConn2.Open()
                cmd2.ExecuteNonQuery()
                gErrorMsg = gErrorMsg & vbCrLf & "<br>dropLSItems sucess: [sellerid:" & gSellerId & "] " & vbCrLf & "<br>last sql:uspDeleteLsItems_BySellerId"
                Return True
            Catch ex As Exception
                gErrorMsg = gErrorMsg & vbCrLf & "<br>dropLSItems fail: [sellerid:" & gSellerId & "] " & ex.Message & vbCrLf & "<br>last sql:uspDeleteLsItems_BySellerId"
                HttpContext.Current.Response.Write("dropLSItems: " & ex.Message & "<br>")
                Return False
            End Try
        End Using

    End Function


Title: Re: ASP.Net (VB) - stored procedure not firing?
Post by: Jason Reed on December 07, 2012, 09:25:01 pm
I'm pretty doubtful that this is the problem, but it looks like in your gErrorMsg line that you are using a variable that is not declared before. The gSellerId which probably has nothing to do with why the sproc is working or not.


Title: Re: ASP.Net (VB) - stored procedure not firing?
Post by: simmo on December 07, 2012, 09:26:45 pm
those are globals (i preface them with g) so they are defined at the start of the class.

however! I need to change that to be the id that the function is passing in, just to be sure it is correct, you may have found it :D (I've modified the code, but won't know till tomorrows run :p takes forever to debug like this)


Title: Re: ASP.Net (VB) - stored procedure not firing?
Post by: simmo on December 08, 2012, 01:13:22 pm
That was it! :doh: It wasn't deleting anything because I was passing in the wrong Id  :lol:


thanks  :happydance:


Title: Re: ASP.Net (VB) - stored procedure not firing? **Resolved**
Post by: Jason Reed on December 08, 2012, 01:41:21 pm
Thus another reason why Global Variables are bad juju.


Title: Re: ASP.Net (VB) - stored procedure not firing? **Resolved**
Post by: simmo on December 08, 2012, 01:47:03 pm
yeah, vbscript taught me a lot of bad habits that .net is getting me out of. I LOVE block level variables now, so when I have to write vbscript, I put everything is sub routines. With that app, I have two id's for each "seller" one for my database, and one for a 3rd party database... I had mine (correct one) in the global, but theirs (wrong one) was being passed in.